Google图表-同一图表上的两个日期系列 [英] Google Chart - two date series on the same chart
问题描述
我有一些日期发生的收入数据:
I have data about earnings occurred on some dates:
['2013-02-13',100],['2013-03-20',200],['2013-04-11',160]
和有关费用的数据发生在其他日期:
and data about costs occurred on some other dates:
['2013-02-22',60],['2013-03-04',90],['2013-03-25',110]
因此,X轴是连续的一个(日期),Y轴表示收益/成本值(数字).我想在同一张图表上代表这两个日期值系列.他们共享相同的时间表,但是事件发生在不同的日期吗?
So X-axis is continuous one (date), and Y-axis represents earning/cost values (number). I'd like to represent these two date-value series on the same chart. They share the same timeline but events occurred on different dates?
这可能吗?
推荐答案
Yes, you just need to join the two data sets, using the google.visualization.data.join method:
var joinedData = google.visualization.data.join(data1, data2, 'full', [[0, 0]], [1], [1]);
如果使用此方法绘制图表,将有两个可以一起绘制的数据系列.请参见以下示例: http://jsfiddle.net/asgallant/XF7JE/
If you draw a chart using this method, you will have two series of data that can be charted together. See this example: http://jsfiddle.net/asgallant/XF7JE/
顺便说一句,使用这样的日期输入,您将获得离散轴而不是连续轴.您需要将日期输入为javascript Date对象以获取连续轴.
Incidentally, with your dates input like that, you will get a discrete axis, not a continuous axis. You need to input the dates as javascript Date objects to get a continuous axis.
这篇关于Google图表-同一图表上的两个日期系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!