• <tfoot id='9bhzG'></tfoot><legend id='9bhzG'><style id='9bhzG'><dir id='9bhzG'><q id='9bhzG'></q></dir></style></legend>
    <i id='9bhzG'><tr id='9bhzG'><dt id='9bhzG'><q id='9bhzG'><span id='9bhzG'><b id='9bhzG'><form id='9bhzG'><ins id='9bhzG'></ins><ul id='9bhzG'></ul><sub id='9bhzG'></sub></form><legend id='9bhzG'></legend><bdo id='9bhzG'><pre id='9bhzG'><center id='9bhzG'></center></pre></bdo></b><th id='9bhzG'></th></span></q></dt></tr></i><div id='9bhzG'><tfoot id='9bhzG'></tfoot><dl id='9bhzG'><fieldset id='9bhzG'></fieldset></dl></div>

    1. <small id='9bhzG'></small><noframes id='9bhzG'>

        • <bdo id='9bhzG'></bdo><ul id='9bhzG'></ul>

      1. Chart js:更新具有两个数据集的折线图

        时间:2023-11-02

            <tbody id='Ju0ED'></tbody>
            <legend id='Ju0ED'><style id='Ju0ED'><dir id='Ju0ED'><q id='Ju0ED'></q></dir></style></legend>
            <i id='Ju0ED'><tr id='Ju0ED'><dt id='Ju0ED'><q id='Ju0ED'><span id='Ju0ED'><b id='Ju0ED'><form id='Ju0ED'><ins id='Ju0ED'></ins><ul id='Ju0ED'></ul><sub id='Ju0ED'></sub></form><legend id='Ju0ED'></legend><bdo id='Ju0ED'><pre id='Ju0ED'><center id='Ju0ED'></center></pre></bdo></b><th id='Ju0ED'></th></span></q></dt></tr></i><div id='Ju0ED'><tfoot id='Ju0ED'></tfoot><dl id='Ju0ED'><fieldset id='Ju0ED'></fieldset></dl></div>

              <tfoot id='Ju0ED'></tfoot>
              • <small id='Ju0ED'></small><noframes id='Ju0ED'>

                  <bdo id='Ju0ED'></bdo><ul id='Ju0ED'></ul>
                  本文介绍了Chart js:更新具有两个数据集的折线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想用两个数据集更新图表 js 中的折线图.我以某种方式设法清空图表,然后能够填写其中一个数据集.但无法使两个数据集都工作.这是代码.

                  I want to update a line chart in chart js with two data sets. I've somehow managed to empty the chart and then able to fill in one of the data set. but unable to make both data sets working. here's the code.

                  ajaxRequest(
                      {
                          url: 'reports/updateChart/?filter=true',
                          method: 'post',
                          data: data
                      }, function (response)
                          {
                              /*refresh the tables with the new data sets*/
                              removeData(myChart);
                              let label = [1, 234, 234, 234, 234, 234, 234, 34, 234, 23, 23, 41, 3, 2, 4];
                              let data = [234, 234, 5, 23, 34, 234, 234, 234],[22, 1, 123, 14, 2]
                          }; addData(myChart, label, data);
                      });
                  
                  });
                  

                  功能:

                  function removeData(chart) {
                      chart.data.labels = [];
                      chart.data.datasets.forEach((dataset) => {
                          dataset.data = [];
                      });
                      chart.update();
                  }
                  
                  function addData(chart, label, data) {
                      $.each(label, function (index, value) {
                          chart.data.labels.push(value);
                      });
                  
                      chart.data.datasets.forEach((dataset) => {
                          $.each(data, function (index, value) {
                              dataset.data.push(value);
                          });
                      });
                      chart.update();
                  }
                  

                  推荐答案

                  我无法找出您的代码的问题,但是您可以参考以下更新图表的方法,该方法与您尝试过的非常相似,但是这是有效的.您也可以参考小提琴 -> http://jsfiddle.net/cuzx3L7j/4/

                  I am not able to find out the issue with your code, but you can refer the below way of updating charts which is very similar to what you have tried but this is working. You can refer the fiddle also -> http://jsfiddle.net/cuzx3L7j/4/

                  希望对你有帮助!

                  function clearAndAddNewDataSets() {
                    myChart.config.data.datasets = [];
                    myChart.config.data.labels = [];
                  
                    var labels = ['Label1', 'Label2', 'Label3', 'Label4', 'Label5', 'Label6', 'Label8', 'Label8'];
                    var data = [
                      [234, 234, 5, 23, 34, 234, 234, 234],
                      [22, 1, 123, 14, 2]
                    ]
                  
                    var colors = ['Red', 'Green'];
                  
                    myChart.config.data.labels = labels;
                  
                    for (i = 0; i < data.length; i++) {
                      var dataSet = {
                        label: 'testLabel' + i,
                        data: data[i],
                        backgroundColor: colors[i]
                      }
                  
                      myChart.config.data.datasets.push(dataSet);
                    }
                  
                    myChart.update();
                  
                  }
                  

                  这篇关于Chart js:更新具有两个数据集的折线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:是否可以使用 vue-chartjs 打印图表? 下一篇:Chartjs 显示标签 &amp;鼠标悬停时的单位统计

                  相关文章

                    • <bdo id='0tqIr'></bdo><ul id='0tqIr'></ul>

                      <small id='0tqIr'></small><noframes id='0tqIr'>

                      <legend id='0tqIr'><style id='0tqIr'><dir id='0tqIr'><q id='0tqIr'></q></dir></style></legend>
                      <i id='0tqIr'><tr id='0tqIr'><dt id='0tqIr'><q id='0tqIr'><span id='0tqIr'><b id='0tqIr'><form id='0tqIr'><ins id='0tqIr'></ins><ul id='0tqIr'></ul><sub id='0tqIr'></sub></form><legend id='0tqIr'></legend><bdo id='0tqIr'><pre id='0tqIr'><center id='0tqIr'></center></pre></bdo></b><th id='0tqIr'></th></span></q></dt></tr></i><div id='0tqIr'><tfoot id='0tqIr'></tfoot><dl id='0tqIr'><fieldset id='0tqIr'></fieldset></dl></div>

                      <tfoot id='0tqIr'></tfoot>