谷歌折线图如何不插入缺失的数据 [英] Google line charts how to NOT interpolate missing data

查看:167
本文介绍了谷歌折线图如何不插入缺失的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一系列事件的数据库表,这些事件具有发生时的日期。现在我想显示每个月的事件数量并以折线图形式显示。
我通过php获取数据并使用data.addrow在循环中生成js代码



现在这个工作正常,但如果有一个月没有事件不会被添加为一行,并且该行只会插入缺失的月份。
因此,例如1月5日事件,2月0日和3月5日事件,将创建一个从一月到三月的水平线,使其看起来像在那里2月份的5个事件。

我怎样才能使行在空月份下降到零?



我是否需要用空填充空行/月?这看起来并不实用。

解决方案

如果您希望该行下降到零,不同的方式。 Google使用 <$为您提供了两种处理空值(空值)的方法c $ c> interpolateNulls 选项:


  1. True 会猜测(图表中的当前行为)

  2. False 会在空数据点的行中留下空缺(不是您想要的)

要让所有空值显示为零,您需要使用for循环检查数据,并将任何空值更改为0.类似下面的代码。

  for(i = 0; i< data.getNumberOfRows(); i ++){ 
if(data.getValue(1,i)== null)
data.setValue(1,i)= 0
}
pre>

上面的代码没有经过测试,我不知道您的数据是如何设置的,所以我没有花太多时间测试它(我没有想法有多少列,等你的数据哈s,您可以根据需要进行调整和测试)。

I have a database table with a series of events, these events have dates for when they happen. Now I would like to display the number of events for each month and show them in a line chart. I get the data via php and generate the js-code in a loop using data.addrow

Now this works fine, but if there is a month with no events it will not be added as a row and the line will simply interpolate the missing month. So for example january 5 events, february 0 and march 5 events, would create a horizontal line going from january to march making it look like there where 5 events in february.

How can i make the line go down to zero for a "empty" month?

Do I need to fill in empty rows/months with null? This would not seem very practical.

解决方案

If you want the line to go down to zero, you are interpolating, just in a different way. Google gives you two ways to deal with empty values (nulls) using the interpolateNulls option:

  1. True will guess what value belongs in between (the current behavior in your chart)
  2. False will leave a break in the line for empty data points (not what you want)

To get all null values to show as zero, you would need to go through your data with a for loop and change any null value to 0. Something like the below code.

for (i = 0; i < data.getNumberOfRows(); i++) {
  if ( data.getValue(1, i) == null )
    data.setValue(1, i) = 0
}

The above code isn't tested, and I don't know how your data is set up so I didn't spend much time testing it (I have no idea how many columns, etc. your data has, you can adjust and test as needed).

这篇关于谷歌折线图如何不插入缺失的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆