首页 \ 问答 \ 使用多个x / y网格动态更新Chart.JS中的散点图/折线图(Dynamicly update scatter/line chart in Chart.JS with multiple x/y grids)

使用多个x / y网格动态更新Chart.JS中的散点图/折线图(Dynamicly update scatter/line chart in Chart.JS with multiple x/y grids)

我想创建一个函数,我可以发送数据推送到我的折线图。 我的功能目前看起来像这样:

function addData(label, xp1, yp1, xp2, yp2) {
  chart.data.labels.push(label);
  chart.data.datasets.data.push({x: xp1, y: yp1}, {x: xp2, y: yp2}); 
  chart.update();
}

label是一个字符串

xp1,xp2,yp1,yp2是双打

我正在运行一个将执行此功能的循环。 什么都没发生,我的图表仍然是空白。

我查看了Chart.js文档 ,它似乎对我的情况没有帮助,看起来它们的示例代码中有错误

这是我的起始代码:

var ctx = document.getElementById('chart').getContext('2d');
var chart = new Chart(ctx, {
    type: 'line',
    data: {
        labels: [''],
        datasets: [{}]
    },
    options: {}
});

这是我希望它一旦填满就会看起来像:

var ctx = document.getElementById('chart').getContext('2d');
var chart = new Chart(ctx, {
    type: 'line',
    data: {
        labels: ['a', 'b', 'c'],
        datasets: [{
            label: 'a',
            fill: false,
            data: [
                {
                    x: 0,
                    y: 9
                }, {
                    x: 3,
                    y: 9
                }
            ]
        },
        {
            label: 'a',
            fill: false,
            data: [
                {
                    x: 3,
                    y: 7
                }, {
                    x: 5,
                    y: 7
                }
            ]
        },
        {
            label: 'c',
            fill: false,
            data: [
                {
                    x: 5,
                    y: 5
                }, {
                    x: 10,
                    y: 5
                }
            ]
        }]
    },
    options: {}
});

I would like to create a function that I can send data to push to my line chart. My function currently looks like this:

function addData(label, xp1, yp1, xp2, yp2) {
  chart.data.labels.push(label);
  chart.data.datasets.data.push({x: xp1, y: yp1}, {x: xp2, y: yp2}); 
  chart.update();
}

label is a string

xp1, xp2, yp1, yp2 are doubles

I am running a loop that will execute this function. Nothing happens and my chart remains blank.

I have looked at the Chart.js docs and it doesn't seem to be helpful for my situation and it appears they have errors in their example code

This is my starting code:

var ctx = document.getElementById('chart').getContext('2d');
var chart = new Chart(ctx, {
    type: 'line',
    data: {
        labels: [''],
        datasets: [{}]
    },
    options: {}
});

This is what I expect it to look like once it's filled in:

var ctx = document.getElementById('chart').getContext('2d');
var chart = new Chart(ctx, {
    type: 'line',
    data: {
        labels: ['a', 'b', 'c'],
        datasets: [{
            label: 'a',
            fill: false,
            data: [
                {
                    x: 0,
                    y: 9
                }, {
                    x: 3,
                    y: 9
                }
            ]
        },
        {
            label: 'a',
            fill: false,
            data: [
                {
                    x: 3,
                    y: 7
                }, {
                    x: 5,
                    y: 7
                }
            ]
        },
        {
            label: 'c',
            fill: false,
            data: [
                {
                    x: 5,
                    y: 5
                }, {
                    x: 10,
                    y: 5
                }
            ]
        }]
    },
    options: {}
});

原文:https://stackoverflow.com/questions/49513143
更新时间:2023-05-28 19:05

最满意答案

一种选择是创建一个扩展Pivot的新类:

use Illuminate\Database\Eloquent\Relations\Pivot;

class DishLocation extends Pivot {
   ...
}

One option is to create a new class that extends the Pivot:

use Illuminate\Database\Eloquent\Relations\Pivot;

class DishLocation extends Pivot {
   ...
}

相关问答

更多
  • 解释此错误 这是Laravel的安全功能。 它旨在保护您在使用批量分配时不受形式操纵。 例如,在注册表单中:当您在数据库中有一个is_admin列时,用户只需操作您的表单即可在服务器上将is_admin设置为true ,从而在数据库中设置为true 。 此安全功能通过使用白名单来定义安全字段来防止这种情况。 如何解决这个问题 您需要在模型上设置$fillable属性。 它的值必须是一个数组,其中包含所有可以批量分配的字段(如用户名,电子邮件地址等)。
  • 根据@iainn的说法,Apache使用的是PHP 7, but the CLI (which Composer uses) is still using 5.6因此尝试再次卸载并安装composer并在安装时选择正确的php版本(7.0)。 检查下面的截图 According to @iainn Apache is using PHP 7, but the CLI (which Composer uses) is still using 5.6 hence, trying to uninstall and ...
  • 在升级指南中,您可以阅读: 在Laravel 5.5中,异常处理程序将所有异常(包括验证异常)转换为HTTP响应。 另外,JSON验证错误的默认格式已更改。 新格式符合以下惯例:... 所以你应该做的是添加到app\Exceptions\Handler.php文件中的以下方法: protected function invalidJson($request, ValidationException $exception) { return response()->json([ 'me ...
  • 我认为id是倒置的。 尝试这个: public function images() { return $this->belongsToMany('App\Images', 'images_stores', 'store_id', 'image_id'); } I think the ids are inverted. Try this: public function images() { return $this->belongsToMany('App\Images', 'images_ ...
  • 一种选择是创建一个扩展Pivot的新类: use Illuminate\Database\Eloquent\Relations\Pivot; class DishLocation extends Pivot { ... } One option is to create a new class that extends the Pivot: use Illuminate\Database\Eloquent\Relations\Pivot; class DishLocation extends P ...
  • 因此,虽然我无法重现原始段错误,但在xdebug未启用时确实发生了另一个。 当我使用以下内容启用xdebug时: sudo phpenmod xdebug sudo service nginx restart 并重新给了我的段错误的脚本,我成功地得到了递归错误的文件名和行号来解决它。 So while I wasn't able to reproduce the original segfault, another one did occur while xdebug wasn't enabled. Wh ...
  • 你尝试在修补匠中使用dd()吗? 我一直在尝试......它对我有用.. 尝试这个 : dd(app('geocoder')->geocode('68.145.37.34')->get()); 回应: Illuminate\Support\Collection {#764 items: array:1 [ 0 => Geocoder\Model\Address {#753 -coordinates: Geocoder\Model\Coordinates {#755 ...
  • 事实上,没有简单的方法来做到这一点。 如果应用程序使用Laravel 5.5功能,则某些部分不起作用,您可能会浪费大量时间来查找和修复这些问题。 在我看来,更便宜的方式将改变主机,事实上,在2017/2018年,使用PHP 7.x比5.6更合理。 如果您查看PHP版本,您将会看到,目前只应用5.6安全修复程序 In fact there is no easy way to do that. If application is using Laravel 5.5 features some parts of ...
  • 你忘了执行查询。 添加->get() : $fruits = Fruit::whereIn('fruit_id',[6,23,5,73])->get(); You forgot to execute the query. Add ->get(): $fruits = Fruit::whereIn('fruit_id',[6,23,5,73])->get();
  • 好吧,如果你去App\Http\Controllers\Auth你有登录和注册控制器,你可以在那里修改它们。 如果你想编辑登录或注册过程,你可以提供想要认证的laravel特性。 或者,如果要修改刀片,请转至resources/views/auth/ ,您会找到registration/login刀片。 对于更多的laravel结构,请遵循以下内容: Laravel okay if you go to App\Http\Controllers\Auth you have Login and Register ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)