具有不匹配x值的多个连续线在图中留下间隙

时间:2013-12-05 00:01:38

标签: charts google-visualization

我使用Google Chart来可视化日期 - 值对。并非所有日期都存在所有值,因此我希望填充空值。但这会在图表中留下空白(红线):

enter image description here

如何获得没有任何跳跃的折线图?

我的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>
      Google Visualization API Sample
    </title>
    <script type="text/javascript" src="//www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load('visualization', '1', {packages: ['corechart']});
    </script>
    <script type="text/javascript">
      function drawVisualization() {
        // Create and populate the data table.
        var data = google.visualization.arrayToDataTable([
          ['x', 'Cats', 'Blanket 1', 'Blanket 2'],
          [new Date(2012),   1,       1,           0.5],
          [new Date(2013),   1,       1,           0.5],
          [new Date(2014),   2,       null,         1],
          [new Date(2015),   4,       2,           0.5],
          [new Date(2016),   4,       3,           0.5],
        ]);

        // Create and draw the visualization.
        new google.visualization.LineChart(document.getElementById('visualization')).
            draw(data, {curveType: "function",
                        width: 500, height: 400,
                        vAxis: {maxValue: 10}}
                );
      }


      google.setOnLoadCallback(drawVisualization);
    </script>
  </head>
  <body style="font-family: Arial;border: 0 none;">
    <div id="visualization" style="width: 500px; height: 400px;"></div>
  </body>
</html>

1 个答案:

答案 0 :(得分:0)

谢谢jmac!用true替换null就是我所需要的:http://jsfiddle.net/nf9wG/

      ['x', 'Cats', 'Blanket 1', 'Blanket 2'],
      [new Date(2012),   1,       1,           0.5],
      [new Date(2013),   1,       1,           0.5],
      [new Date(2014),   2,       true,         1],
      [new Date(2015),   4,       2,           0.5],
      [new Date(2016),   4,       3,           0.5],