admin管理员组文章数量:1307509
Having a dimple grouped bar chart, with sometimes two records per serie, I would like to stack the values for the same "Channel" like in a stacked grouped bar chart, whilst keeping the colors and legend like in the grouped bar chart (i.e. legend based on the "Channel").
Example
The red bars on the right of each graph show the data for hypermarkets. Data are like:
{"Price Tier":"Regular","Channel":"Hypermarkets","Unit Sales":"5489","Status":"Actual"},
{"Price Tier":"Regular","Channel":"Hypermarkets","Unit Sales":"1651","Status":"Future"},
(a) standard. We get this kind of display with var x = myChart.addCategoryAxis("x", ["Price Tier", "Channel"]);
(b) overlaid. We get this kind of display with var x = myChart.addCategoryAxis("x", ["Price Tier", "Channel", "Status"]);
(c) stacked. This is what I want to achieve: stacking bars instead of overlaying them, whilst keeping the same color for the bars. Bars for the dimension Unit Sales
5489
and 1651
should when stacked reach the total height of 7140
, like in standard chart.
(d) optimal is the ideal case for my needs: stacked bars with some additional transparency for future (expected) values.
How can I make my graph evolve from (b) overlaid bars to (c) stacked ones?
Better edit dimple's source code, or should one use series.afterDraw
?
Then, for the optimal display, should one use series.afterDraw
to only to reach the last element and alter its transparency?
SOLUTION - I found a solution to my question, that allows graphs (c) and (d) by using a stacked grouped bar chart, and using a workaround. See my answer to my own question below. For developers, I think my question can still bring idea for code optimization in dimple.js for standard grouped bar charts, that would allow to implement the idea in a more elegant way, without the workaround found.
Having a dimple grouped bar chart, with sometimes two records per serie, I would like to stack the values for the same "Channel" like in a stacked grouped bar chart, whilst keeping the colors and legend like in the grouped bar chart (i.e. legend based on the "Channel").
Example
The red bars on the right of each graph show the data for hypermarkets. Data are like:
{"Price Tier":"Regular","Channel":"Hypermarkets","Unit Sales":"5489","Status":"Actual"},
{"Price Tier":"Regular","Channel":"Hypermarkets","Unit Sales":"1651","Status":"Future"},
(a) standard. We get this kind of display with var x = myChart.addCategoryAxis("x", ["Price Tier", "Channel"]);
(b) overlaid. We get this kind of display with var x = myChart.addCategoryAxis("x", ["Price Tier", "Channel", "Status"]);
(c) stacked. This is what I want to achieve: stacking bars instead of overlaying them, whilst keeping the same color for the bars. Bars for the dimension Unit Sales
5489
and 1651
should when stacked reach the total height of 7140
, like in standard chart.
(d) optimal is the ideal case for my needs: stacked bars with some additional transparency for future (expected) values.
How can I make my graph evolve from (b) overlaid bars to (c) stacked ones?
Better edit dimple's source code, or should one use series.afterDraw
?
Then, for the optimal display, should one use series.afterDraw
to only to reach the last element and alter its transparency?
SOLUTION - I found a solution to my question, that allows graphs (c) and (d) by using a stacked grouped bar chart, and using a workaround. See my answer to my own question below. For developers, I think my question can still bring idea for code optimization in dimple.js for standard grouped bar charts, that would allow to implement the idea in a more elegant way, without the workaround found.
Share Improve this question edited Feb 2 at 18:12 OuzoPower asked Feb 2 at 16:16 OuzoPowerOuzoPower 2781 gold badge2 silver badges12 bronze badges 1 |1 Answer
Reset to default 0A solution to have dimple stacked bars with control over the columns color is possible with this trick:
Make stacked grouped bar chart instead of a grouped bar chart. In the example, instead of
myChart.addSeries("Channel", dimple.plot.bar);
we set them according one of the values of the dimension to plot:myChart.addSeries("Status", dimple.plot.bar);
Then, we set for the series to plot ("Status") instead of returning the value "Actual", we return column name (the value for "Channel") where the serie will be to be plotted.
Instead of
{"Price Tier":"Regular","Channel":"Hypermarkets","Unit Sales":"5489","Status":"Actual"},
{"Price Tier":"Regular","Channel":"Hypermarkets","Unit Sales":"1651","Status":"Future"},
we feed the graph with
{"Price Tier":"Regular","Channel":"Hypermarkets","Unit Sales":"5489","Status":"Hypermarkets"},
{"Price Tier":"Regular","Channel":"Hypermarkets","Unit Sales":"1651","Status":"Hypermarkets (forecast)"},
So, we bound the "Channel" and "Status" columns in kind of 1-to-1 relationship, and have one additional serie "Hypermarkets (forecast)" (that also appears in the legend), that we will then can style independantly.
本文标签: stackedStack records per serie in a dimple vertical grouped bar chartStack Overflow
版权声明:本文标题:stacked - Stack records per serie in a dimple vertical grouped bar chart - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741841773a2400543.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
mySeries.stacked = true;
as having found a solution meanwhile, but could be worth trying. – OuzoPower Commented Feb 2 at 18:55