散点图在x轴上复制相同的值

时间:2018-01-10 06:33:39

标签: php ajax google-visualization scatter-plot

我正在使用ajax调用绘制散点图。一些值在x轴上重复,而y轴值不同。示例 -

bucket_type

在上面的示例中,x轴上的年份值是重复的(2015年和2016年)。散点图为2015年和2015年提取了2个点。同样的2016年。 enter image description here 我想用不同的y轴值显示单个x轴值。

图表输出应该像 - enter image description here

感谢任何帮助。感谢。

3 个答案:

答案 0 :(得分:0)

2015年和2016年的行有两个条目。

    "rows":
        [{"c":[{"v":"2006","f":null},{"v":"0","f":"$0"}]},{"c":
[{"v":"2007","f":null},{"v":"0","f":"$0"}]},{"c":[{"v":"2008","f":null},
{"v":"0","f":"$0"}]},{"c":[{"v":"2009","f":null},{"v":"0","f":"$0"}]},{"c":
[{"v":"2010","f":null},{"v":"0","f":"$0"}]},{"c":[{"v":"2011","f":null},
{"v":"0","f":"$0"}]},{"c":[{"v":"2012","f":null},{"v":"0","f":"$0"}]},{"c":
[{"v":"2013","f":null},{"v":"0","f":"$0"}]},{"c":[{"v":"2014","f":null},
{"v":"0","f":"$0"}]}, <Repeated part starts here -------{"c":[{"v":"2015","f":null},{"v":"10700","f":"$10,700"}]},
{"c":[{"v":"2015","f":null},{"v":"1280","f":"$1,280"}]},{"c":
[{"v":"2016","f":null},{"v":"2500","f":"$2,500"}]},{"c":[{"v":"2016","f":null},
{"v":"80500","f":"$80,500"}]} ------Repeated part ends here>]}

答案 1 :(得分:0)

嗨请试试这个,

"rows": [{"c":[{"v":"2006","f":0}]},
         {"c":[{"v":"2007","f":0}]},
         {"c":[{"v":"2008","f":0}]},
         {"c":[{"v":"2009","f":0}]},
         {"c":[{"v":"2010","f":0}]},
         {"c":[{"v":"2011","f":0}]},
         {"c":[{"v":"2012","f":0}]},
         {"c":[{"v":"2013","f":0}]},
         {"c":[{"v":"2014","f":0}]},
         {"c":[{"v":"2015","f":1280}]},
         {"c":[{"v":"2016","f":80500}]}
        ]

请参阅下面提到的链接js fiddle working file

答案 2 :(得分:0)

我已按以下方式更改了ajax响应中的json格式 -

[["Sold Year","Unit Price"],[2006,0],[2007,0],[2008,0],[2009,0],[2010,0],[2011,0],[2012,0],[2013,0],[2014,0],[2015,10700],[2015,1280],[2016,2500],[2016,80500]]

现在它按预期工作了。谢谢大家的建议。