首页 \ 问答 \ ChartJS折线图导致浏览器崩溃(ChartJS Line chart causes browser crash)

ChartJS折线图导致浏览器崩溃(ChartJS Line chart causes browser crash)

我正在使用HTTP get ngResource和rest API更新折线图。 我的技术是获取JSON数据集并在每次用户单击按钮时创建新图表。 它运行良好,但同时,它会导致浏览器崩溃。 我已经在Windows和Linux上测试了Chrome,Firefox。

在我的控制器中:

$scope.labels = $scope.dataFromREST;
$scope.series = ['Series A'];
$scope.data = [$scope.dataFromREST2];
$scope.onClick = function (points, evt) {
    console.log(points, evt);
};
$scope.datasetOverride = [{ yAxisID: 'y-axis-1' }];
$scope.options = {
    scales: {
        yAxes: [
            {
                id: 'y-axis-1',
                type: 'linear',
                display: true,
                position: 'left'

            }
        ],
        xAxes: [{
            responsive: true,
            ticks: {
                autoSkip: true,
                maxTicksLimit: 20
            }
        }]

    }

};

在我的index.html中:

<canvas id="line" class="chart chart-line" chart-data="data"
                    chart-labels="labels" chart-series="series" chart-options="options"
                    chart-dataset-override="datasetOverride" chart-click="onClick">
            </canvas>

有没有办法只使用收到的$ scope.dataFromREST数据更新或刷新折线图,而不是每次都创建一个新的Chart对象? (因为我认为,崩溃来自每次创建一个新图表)我看到“.update()”函数,但我似乎无法让它工作。 我也试过“.destroy()”,我仍然让浏览器崩溃。

我该如何摆脱那次崩溃? 请帮忙!


I am updating a Line chart using HTTP get through ngResource and a rest API. My technique is to get the JSON dataset and create a new chart every time a user is clicking on a button. It works great, but at one time, it causes the browser crash. I have tested on Chrome, Firefox on both Windows and Linux.

In my controller :

$scope.labels = $scope.dataFromREST;
$scope.series = ['Series A'];
$scope.data = [$scope.dataFromREST2];
$scope.onClick = function (points, evt) {
    console.log(points, evt);
};
$scope.datasetOverride = [{ yAxisID: 'y-axis-1' }];
$scope.options = {
    scales: {
        yAxes: [
            {
                id: 'y-axis-1',
                type: 'linear',
                display: true,
                position: 'left'

            }
        ],
        xAxes: [{
            responsive: true,
            ticks: {
                autoSkip: true,
                maxTicksLimit: 20
            }
        }]

    }

};

In my index.html :

<canvas id="line" class="chart chart-line" chart-data="data"
                    chart-labels="labels" chart-series="series" chart-options="options"
                    chart-dataset-override="datasetOverride" chart-click="onClick">
            </canvas>

Is there a way to just update or refresh the Line Chart with the $scope.dataFromREST data received and not create a new Chart object every time? (Because I think, the crash come from creating a new chart every time) I see the ".update()" function, but I can't seem to get it to work. I have also tried the ".destroy()" and I am still getting the browser wind up to crash.

How can I get rid of that crash? Please help!


原文:https://stackoverflow.com/questions/42448170
更新时间:2021-09-23 06:09

最满意答案

对我来说这看起来像个错误。 如果我们省略类型注释(无论如何都不需要):

let a = A()
let b = (a * a) * B()

然后编译器抱怨“模糊使用”:

main.swift:14:12: error: ambiguous reference to member '*'
let b = (a * a) * B()
           ^
main.swift:7:6: note: found this candidate
func *(left: A, right: A) -> A { return A() }
     ^
main.swift:8:6: note: found this candidate
func *(left: A, right: B) -> B { return B() }
     ^
Swift.Float:4:24: note: found this candidate
    public static func *(lhs: Float, rhs: Float) -> Float
                       ^
Swift.Double:4:24: note: found this candidate
    public static func *(lhs: Double, rhs: Double) -> Double

Swift.Float80:4:24: note: found this candidate
    public static func *(lhs: Float80, rhs: Float80) -> Float80
                       ^
Swift.UInt8:234:24: note: found this candidate
    public static func *(lhs: UInt8, rhs: UInt8) -> UInt8
                       ^
Swift.Int8:234:24: note: found this candidate
    public static func *(lhs: Int8, rhs: Int8) -> Int8

// ... and many more  ...

这是没有意义的,因为那些重载不适用于两个A操作数。

似乎编译器“混淆”了,因为*运算符有太多重载的定义。 使用自定义运算符不会出现此问题,此编译没有问题:

infix operator <*>: MultiplicationPrecedence

struct A { }
struct B { }

func <*>(left: A, right: A) -> A { return A() }
func <*>(left: A, right: B) -> B { return B() }

let a = A()
let b = (a <*> a) <*> B()

我建议在https://bugs.swift.org上提交一个错误,并使用中间变量:

let a = A()
let a2 = a * a
let b = a2 * B()

或中间演员:

let a = A()
let b = ((a * a) as A) * B()

作为一种解决方法。


This looks like a bug to me. If we omit the type annotation (which should not be necessary anyway):

let a = A()
let b = (a * a) * B()

then the compiler complains about "ambiguous use":

main.swift:14:12: error: ambiguous reference to member '*'
let b = (a * a) * B()
           ^
main.swift:7:6: note: found this candidate
func *(left: A, right: A) -> A { return A() }
     ^
main.swift:8:6: note: found this candidate
func *(left: A, right: B) -> B { return B() }
     ^
Swift.Float:4:24: note: found this candidate
    public static func *(lhs: Float, rhs: Float) -> Float
                       ^
Swift.Double:4:24: note: found this candidate
    public static func *(lhs: Double, rhs: Double) -> Double

Swift.Float80:4:24: note: found this candidate
    public static func *(lhs: Float80, rhs: Float80) -> Float80
                       ^
Swift.UInt8:234:24: note: found this candidate
    public static func *(lhs: UInt8, rhs: UInt8) -> UInt8
                       ^
Swift.Int8:234:24: note: found this candidate
    public static func *(lhs: Int8, rhs: Int8) -> Int8

// ... and many more  ...

which makes no sense, because those overloads are not applicable to two A operands.

It seems that the compiler is "confused" because there are so many overloaded definitions for the * operator. The problem does not occur with a custom operator, this compiles without problems:

infix operator <*>: MultiplicationPrecedence

struct A { }
struct B { }

func <*>(left: A, right: A) -> A { return A() }
func <*>(left: A, right: B) -> B { return B() }

let a = A()
let b = (a <*> a) <*> B()

I recommend to file a bug at https://bugs.swift.org, and use intermediate variables:

let a = A()
let a2 = a * a
let b = a2 * B()

or intermediate casts:

let a = A()
let b = ((a * a) as A) * B()

as a workaround.

相关问答

更多
  • std::endl是一个函数, std::cout通过实现operator<<来获取与std::endl相同签名的函数指针。 在那里,它调用该函数,并转发返回值。 这是一个代码示例: #include struct MyStream { template MyStream& operator<<(const T& x) { std::cout << x; return *this; } ...
  • 当为流重载时,你向全局声明一个<<运算符和/或作为friend (带有好处),以便它可以访问它的'私有成员'(哦......)。 您可以在类中声明一个friend来全局声明它。 不要在流上使用const 。 接下来,在重载中使用传递的流。 在你的方法中,你只需要使用stream参数就可以使用cout 。 我没有测试过这个,但看看它是否适合你。 class sex_t { private: char __sex__; public: sex_t(char sex_v = 'M'):__sex_ ...
  • 如果要直接查看类型的具体“=”运算符,则必须使其可见。 为此,您需要“使用”或“使用类型”。 package Newq is new Queue(Integer,Integer); use type newq.Queue; 参考 Ada:操作员无法直接看到 Ada可见性规则:使用条款 if you want direct visibility to a type's concrete "=" operator, you have to make it visible. For that you need ...
  • 对于以下内容,您需要一个复制构造函数。 它不使用赋值运算符函数。 myString g = s; 编辑 对于链接器错误 - 我无法帮助你。 而不是猜测哪一个operator<<该行调用,我将放弃这个,因为你没有提供代码。 在普通的C ++代码中,没有办法简单的cout << this; 会导致链接器错误。 cout有一个接受void const*的运算符。 您已在某处声明了一个提供更好匹配但未定义它的运算符。 For the following, you need a copy constructor. ...
  • 您不能将operator >>作为成员函数进行重载。 定义为成员函数的任何运算符都将其第一个参数作为对(const)Type的引用,其中Type是您的类名 - 在本例中为电话簿。 你需要改变 istream &phonebook::operator>>(istream &in, phonebook &book) 至 istream & operator>>(istream &in, phonebook &book) You cannot overload operator >> for streamin ...
  • 看看template class TT 。 此参数适用于模板,任何接受任意数量类型参数的模板。 现在看看std::array 。 此模板不接受类型作为第二个参数。 它接受一个积分常数。 所以它不能成为你定义的模板函数的一个参数,并且模板参数推导失败了。 至于使其工作,最简单的方法是提供只接受std::array的(模板化)重载。 模板参数将是(推导的)数组参数。 template os ...
  • 您的命名空间不匹配。 在标头中,您不在string之前使用std名称空间前缀,因此编译器无法找到您需要的类型string 。 You have namespaces mismatch. In the header you do not use the std namespace prefix before string thus the compiler can't find the type string that you need.
  • 你需要: ostream & operator<<(ostream& out, const animal& rhs) 在您的代码中您正在尝试修改const ostream对象,因此您会收到错误。 它不应该是const 。 You need to have: ostream & operator<<(ostream& out, const animal& rhs) In your code You are trying to modify a const ostream object, and so yo ...
  • 它是你创建运算符的方式,它试图重新定义使用shift-left和两个整数意味着什么,而不是你的类。 你想要这样的东西: friend int operator<<(const bitwise& , int); The way you are creating the operator, it is trying to redefine what it means to use shift-left with two integers, and not with your class. You want s ...
  • 对我来说这看起来像个错误。 如果我们省略类型注释(无论如何都不需要): let a = A() let b = (a * a) * B() 然后编译器抱怨“模糊使用”: main.swift:14:12: error: ambiguous reference to member '*' let b = (a * a) * B() ^ main.swift:7:6: note: found this candidate func *(left: A, right: A) -> A { ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。