admin管理员组文章数量:1332383
How do I create a Google Combo Chart that replicates the image below? It seems once I add the column for the vertical line the green columns lose their groupWidth property and turn into skinny lines.
data.addColumn('number', 'X');
data.addColumn('number', 'Y');
data.addColumn('number', 'Average');
data.addColumn('number', 'Vertical Line');
data.addRows([
[1, 5, 3, null],
[3, 4, 3, null],
[5, 2, 3, null],
[2, null, null, 0], // add vertical line
[2, null, null, 5],
]);
Here is a jsfiddle: /
How do I create a Google Combo Chart that replicates the image below? It seems once I add the column for the vertical line the green columns lose their groupWidth property and turn into skinny lines.
data.addColumn('number', 'X');
data.addColumn('number', 'Y');
data.addColumn('number', 'Average');
data.addColumn('number', 'Vertical Line');
data.addRows([
[1, 5, 3, null],
[3, 4, 3, null],
[5, 2, 3, null],
[2, null, null, 0], // add vertical line
[2, null, null, 5],
]);
Here is a jsfiddle: http://jsfiddle/vmb4odkt/
Share asked Apr 2, 2015 at 18:59 wwwuserwwwuser 6,37210 gold badges57 silver badges65 bronze badges1 Answer
Reset to default 8 +100The whole thing can use some cleanup especially depending on your final data, but here's a good solution I think. I used the inspection methods to find out where on the chart's div the line should go and then add a new div to draw the line over the SVG chart. You can similarly add an SVG node to the SVG element in the DOM.
http://jsfiddle/vmb4odkt/2/
I had to make the container div position: relative
to make calculations easier.
The main code is this:
var line = document.createElement("div");
var interface = chart.getChartLayoutInterface();
var cli = chart.getChartLayoutInterface();
line.style.background = "red";
line.style.width = "2px";
line.style.position = "absolute";
line.style.left = (interface.getXLocation(2) - 1) + "px";
line.style.top = interface.getYLocation(5) + "px";
line.style.height = (interface.getYLocation(1) - interface.getYLocation(5)) + "px";
el.appendChild(line);
All of the hardcoded values can be removed and replaced with either calculations or constants depending on your data source.
本文标签: javascriptGoogle Combo Chart add horizontal and vertical line in column chartStack Overflow
版权声明:本文标题:javascript - Google Combo Chart add horizontal and vertical line in column chart - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742295340a2448612.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论