如何使用Google Visualization API描述日线图?

发布于 2024-10-22 21:03:14 字数 1862 浏览 2 评论 0原文

我试图用以下方式描述每日折线图 谷歌可视化 API。 http://code.google.com/apis/visualization/documentation/reference.html

DataTable 对象是这样的。

[
{date:'3/1', value:'1000'},  
{date:'3/2', value:'1500'},  
{date:'3/3', value:'1200'},  
{date:'3/4', value:'1300'},  
{date:'3/5', value:'1400'},  
{date:'3/6', value:'1100'},  
{date:'3/7', value:'1200'}
]

通过上面的数据,图表显示了一周的记录。

即使缺少一些数据,我也想描述一个周图。

[
{date:'3/1', value:'1000'},  
{date:'3/2', value:'1500'},  
{date:'3/5', value:'1400'},  
{date:'3/7', value:'1200'}  
]

我想用上面的数据描述一个周图,这意味着x轴应该有7天,并且 如果没有数据,该行应该是 仅与现有数据连接。


感谢您提供的信息。我尝试了“interpolateNulls”,但没有按我的预期工作。

对于下面的代码,换行符位于 3/2 和 3/4 之间。 我想要连接 3/2-3/4。

<html>
  <head>
    <script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>
    google.load("visualization", "1.0", {packages:["imagechart"]});
    </script>
    <script type='text/javascript'>
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var dataTable = new google.visualization.DataTable();
        dataTable.addColumn('string');
        dataTable.addColumn('number');
        var data = [['3/1',1000],['3/2',1300],['3/3',null],['3/4',1800],['3/5',900],['3/6',1200],['3/7',1000]];
        dataTable.addRows(data);
        var options = {cht: 'lc', chds:'0,3000', interpolateNulls: true};

        var chart = new google.visualization.ImageChart(document.getElementById('chart_div'));
        chart.draw(dataTable, options);
      }
    </script>
  </head>
  <body>
    <div id='chart_div'></div>
  </body>
</html>

I'm trying to describe daily line chart with
Google Visualization API.
http://code.google.com/apis/visualization/documentation/reference.html

DataTable object is something like this.

[
{date:'3/1', value:'1000'},  
{date:'3/2', value:'1500'},  
{date:'3/3', value:'1200'},  
{date:'3/4', value:'1300'},  
{date:'3/5', value:'1400'},  
{date:'3/6', value:'1100'},  
{date:'3/7', value:'1200'}
]

With the data above, the graph shows a week records.

I want to describe a week chart even when some data lack.

[
{date:'3/1', value:'1000'},  
{date:'3/2', value:'1500'},  
{date:'3/5', value:'1400'},  
{date:'3/7', value:'1200'}  
]

I want to describe a week chart with the data above, that means there should be 7 days for x-axis, and
in the case there is no data, the line should be
connected only with existing data.


Thank you for your information. I tried 'interpolateNulls' but doesn't work as I expected.

With the code below, the line break between 3/2 and 3/4.
I want 3/2-3/4 to be connected.

<html>
  <head>
    <script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>
    google.load("visualization", "1.0", {packages:["imagechart"]});
    </script>
    <script type='text/javascript'>
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var dataTable = new google.visualization.DataTable();
        dataTable.addColumn('string');
        dataTable.addColumn('number');
        var data = [['3/1',1000],['3/2',1300],['3/3',null],['3/4',1800],['3/5',900],['3/6',1200],['3/7',1000]];
        dataTable.addRows(data);
        var options = {cht: 'lc', chds:'0,3000', interpolateNulls: true};

        var chart = new google.visualization.ImageChart(document.getElementById('chart_div'));
        chart.draw(dataTable, options);
      }
    </script>
  </head>
  <body>
    <div id='chart_div'></div>
  </body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

漫雪独思 2024-10-29 21:03:14

包括一周中每个日期的条目,并将缺失的值设置为 null。

[
{date:'3/1', value:'1000'},  
{date:'3/2', value:'1500'},   
{date:'3/3', value: null }, 
{date:'3/4', value: null }, 
{date:'3/5', value:'1400'},  
{date:'3/7', value:'1200'}  
]

行字符的配置选项之一是 interpolateNulls。 使用

interpolateNulls: True

在您的绘制方法中 。编辑:图表类型必须是 LineChart 而不是 ImageLineChart 才能使 interpolateNulls 工作。

有关配置选项的文档位于此处

Include an entry for every date of the week and set the value of the missing ones as null.

[
{date:'3/1', value:'1000'},  
{date:'3/2', value:'1500'},   
{date:'3/3', value: null }, 
{date:'3/4', value: null }, 
{date:'3/5', value:'1400'},  
{date:'3/7', value:'1200'}  
]

One of the configuration options for the line char is interpolateNulls. Use

interpolateNulls: True

in your draw method. EDIT: The chart type must be a LineChart rather than an ImageLineChart for interpolateNulls to work.

Documentation on the configuration options is here.

再可℃爱ぅ一点好了 2024-10-29 21:03:14

在我看来,只需在循环内创建一个控制结构来验证所有值。foreach 值验证它是否为 null

  • 这些数据是如何生成的?
  • 您是从某处读取的,还是手动输入的?

在你的图表中:

chart.draw(data, {interpolateNulls: True, width: 400, height: 240, title: 'Company Performance'});

我不测试自己,我希望这有帮助。

In my opnion just create a structure of control inside a loop to verify all values.. foreach value verify if it is null.

  • How those datas is generated?
  • Do you read it from somewhere, or it is input by hand?

In your chart:

chart.draw(data, {interpolateNulls: True, width: 400, height: 240, title: 'Company Performance'});

I do not test myself, I hope this help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文