Google散点图中的水平线

发布于 2025-01-01 08:42:21 字数 128 浏览 5 评论 0原文

我使用散点图来显示具有以下范围的数据: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 技术交流群。

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

发布评论

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

评论(1

花心好男孩 2025-01-08 08:42:21

我们在工作中也遇到了同样的问题。不幸的是,目前 Google Charts 还没有提供一种简单的方法来在散点图中显示一条线,就像在条形图中一样。

最后我们找到了一个非常适合我们的“小技巧”,正如您在这里看到的:
技巧

在于创建一条“线”图表”,但将一系列点中的 linewidth 属性设置为 0,pointsize 设置为 5,linewidth 1 和行系列中的pointsize 0。
看起来像:

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 }
        }

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

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

而这个系列的“点”(最后一个系列):

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

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

我希望我已经解释了它清楚了,如果您还有其他问题,请告诉我。

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.

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