how to start stacked bars from a negative value?

陌路散爱 提交于 2019-12-11 10:47:58

问题


I am trying to create a stacked bars chart in dimple.js with the stacked bar starting from a negative position.

Is there any property of the chart that does this or is there any tweak that we can put into dimple.js file?


回答1:


That's a slightly unusual requirement and dimple doesn't support it as a simple property, however you can create the impression of a bar starting below zero by using a fake axis. Here's an example with accompanying fiddle to show what I mean:

var svg = dimple.newSvg("#chartContainer", 600, 400);
var data = [
    { bar: "A", value: "100" },
    { bar: "B", value: "110" },
    { bar: "C", value: "120" },
    { bar: "D", value: "130" }
    ];
var chart = new dimple.chart(svg, data);
var x = chart.addCategoryAxis("x", "bar");
var y1 = chart.addMeasureAxis("y", "My Fake Axis Title");
var y2 = chart.addMeasureAxis("y", "value");
y1.overrideMin = -100;
y1.overrideMax = 200;
y2.overrideMin = -10;
y2.hidden = true;
chart.addSeries(null, dimple.plot.bar, [x, y2]);
chart.draw();

http://jsfiddle.net/LVKfa/1/



来源:https://stackoverflow.com/questions/20673476/how-to-start-stacked-bars-from-a-negative-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!