最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Visualisation Line Chart - Multiple Lines - Stack Overflow

programmeradmin1浏览0评论

I have a line chart, h-axis is date, v-axis is double. I need to display two lines:

lineA: [
    [2016-1-1 00:00, 1.1]
    [2016-2-1 00:00, 1.1]
    [2016-3-1 00:00, 1.1]
]
lineB: [
    [2016-1-1 00:00, 2.1]
    [2016-2-1 08:00, 2.1]
    [2016-3-1 00:00, 2.1]
]

To display the data on the chart, I need to bine these two lines and pass the result to arrayToDataTable.

bine: [
    [2016-1-1 00:00, 1.1, 2.1],
    [2016-2-1 00:00, 1.1, null],
    [2016-2-1 08:00, null, 2.1],
    [2016-3-1 00:00, 1.1, 2.1],
]

As a result of the above, I am getting gaps on the lines. How can I solve this issue? Is it possible to pass two individual sets, one for each line? All the examples I have found require them to be merged as the bine table.

I need to keep the nulls when provided as part of line1 and line2 table

I have a line chart, h-axis is date, v-axis is double. I need to display two lines:

lineA: [
    [2016-1-1 00:00, 1.1]
    [2016-2-1 00:00, 1.1]
    [2016-3-1 00:00, 1.1]
]
lineB: [
    [2016-1-1 00:00, 2.1]
    [2016-2-1 08:00, 2.1]
    [2016-3-1 00:00, 2.1]
]

To display the data on the chart, I need to bine these two lines and pass the result to arrayToDataTable.

bine: [
    [2016-1-1 00:00, 1.1, 2.1],
    [2016-2-1 00:00, 1.1, null],
    [2016-2-1 08:00, null, 2.1],
    [2016-3-1 00:00, 1.1, 2.1],
]

As a result of the above, I am getting gaps on the lines. How can I solve this issue? Is it possible to pass two individual sets, one for each line? All the examples I have found require them to be merged as the bine table.

I need to keep the nulls when provided as part of line1 and line2 table

Share Improve this question edited Apr 24, 2017 at 17:05 WhiteHat 61.3k7 gold badges53 silver badges136 bronze badges asked Jan 20, 2017 at 15:51 GiannisGiannis 5,52616 gold badges64 silver badges117 bronze badges 2
  • You need to consider only the date part. Try check stackoverflow./questions/2698725/… – Nizam Commented Jan 20, 2017 at 15:55
  • Time is important, I can't drop it. – Giannis Commented Jan 20, 2017 at 15:56
Add a ment  | 

1 Answer 1

Reset to default 5

use the following option to fill in gaps created by null values

interpolateNulls: true

EDIT

see following working snippet...

google.charts.load('current', {
  callback: function () {
    var data = google.visualization.arrayToDataTable([
      [new Date(2016, 0, 1), 1.1, 2.1],
      [new Date(2016, 1, 1), 1.1, null],
      [new Date(2016, 1, 1, 8), null, 2.1],
      [new Date(2016, 2, 1), 1.1, 2.1]
    ], true);

    var options = {
      interpolateNulls: true
    };

    var container = document.body.appendChild(document.createElement('div'));
    var chart = new google.visualization.LineChart(container);
    chart.draw(data, options);
  },
  packages: ['corechart']
});
<script src="https://www.gstatic./charts/loader.js"></script>

发布评论

评论列表(0)

  1. 暂无评论