Google散点图中的水平线 [英] Horizontal line in Google scatter chart

查看:159
本文介绍了Google散点图中的水平线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用散点图来显示具有以下范围的数据: x = [-1..1] y = [-1..1] 。是否可以在例如水平线上画一条水平线? y = 0.5
我使用JavaScript图表(即不是图表图表)。

解决方案

我们在工作。不幸的是,目前谷歌图表并没有提供简单的方式在散点图中显示一条线,就像条形图一样。



最后,我们发现了一个小动作这对我们来说非常合适,你可以在这里看到:
http://csgid.org/ csgid / statistics / structures



诀窍在于创建折线图,但将 linewidth 属性设置为0和 pointsize 设为5,并且线条系列中的 linewidth 1和 pointsize 0。
它看起来像:

  interpolateNulls:true,
系列:{
0:{ lineWidth:0,pointSize:5},
1:{lineWidth:0,pointSize:5},
2:{lineWidth:0,pointSize:5},
3:{lineWidth: 0,pointSize:5},
4:{lineWidth:1,pointSize:0}
}

为什么我将 interpolateNulls 设置为true?因为那样,我必须改变我在数组中设置数据的方式,然后再将其转换为JSON并传递给Google Charts。在每一行中,我必须为X轴的每个值设置每个系列的值。所以当一个系列没有X值的Y值时(我的意思是,当一个系列对这个X值没有任何意义时),我必须将X值设为null。所以,对于该系列的系列也是如此。
这将是第一个系列(以JSON)的一个点:

  [2.6,0.184,null,null ,null,null] 

这一行系列(最后一个系列)的点:

  [4,null,null,null,null,0.254] 
pre>

也许这不是最有效的方法,但它可以工作:)

我希望我已经解释过很明显,让我知道你是否有更多问题。

I'm using a scatter chart to display data with the following range: x = [-1..1] y = [-1..1]. Is it possible to draw a horizontal line on e.g. y = 0.5? I'm using the JavaScript charts (i.e. not the image charts).

解决方案

We had the same problem at work. Unfortunately, for the moment Google Charts does not provide an easy way to display a line in the scatter chart, like in the bar chart.

Finally we found a "small trick" that works perfectly for us, as you can see here: http://csgid.org/csgid/statistics/structures

The trick consist in creating a "Line chart" but setting the linewidth property to 0 and pointsize to 5 in the series of the points, and linewidth 1 and pointsize 0 in the serie of the line. It looks like:

interpolateNulls: true,
        series: {
          0: { lineWidth: 0, pointSize: 5 },
          1: { lineWidth: 0, pointSize: 5 },
          2: { lineWidth: 0, pointSize: 5 },
          3: { lineWidth: 0, pointSize: 5 },   
          4: { lineWidth: 1, pointSize: 0 }
        }

Why did I set interpolateNulls to true? Because then, I had to change the way I was setting the data in the array before convert it to JSON and pass it to Google Charts. In every row I had to set the values of every serie in the X axis for each value of the Y axis. So I had to set to null the X value when a serie didn't have a Y value for that X value (I mean, when a serie didn't have any point for that X value). So, the same for the serie of the line. This would be one point of the first serie (in JSON):

[2.6,0.184,null,null,null,null]

And this one "point" of the line serie (the last serie):

[4,null,null,null,null,0.254]

Maybe it is not the most efficient way, but it works :)

I hope I have explained it clear, let me know if you have more questions.

这篇关于Google散点图中的水平线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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