Google散点图中的水平线
我使用散点图来显示具有以下范围的数据:x = [-1..1] y = [-1..1]
。是否可以在例如y = 0.5
上画一条水平线? 我正在使用 JavaScript 图表(即不是图像图表)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们在工作中也遇到了同样的问题。不幸的是,目前 Google Charts 还没有提供一种简单的方法来在散点图中显示一条线,就像在条形图中一样。
最后我们找到了一个非常适合我们的“小技巧”,正如您在这里看到的:
技巧
在于创建一条“线”图表”,但将一系列点中的 linewidth 属性设置为 0,pointsize 设置为 5,linewidth 1 和行系列中的pointsize 0。
看起来像:
为什么我将 interpolateNulls 设置为 true?因为那时,我必须更改在数组中设置数据的方式,然后将其转换为 JSON 并将其传递到 Google Charts。在每一行中,我必须为 Y 轴的每个值设置 X 轴中每个系列的值。因此,当一个系列没有该 X 值的 Y 值时(我的意思是,当一个系列没有该 X 值的任何点时),我必须将 X 值设置为 null。所以,该系列的产品线也是如此。
这将是第一个系列的一个点(在 JSON 中):
而这个系列的“点”(最后一个系列):
也许这不是最有效的方法,但它有效:)
我希望我已经解释了它清楚了,如果您还有其他问题,请告诉我。
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:
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):
And this one "point" of the line serie (the last serie):
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.