Hi Minh Chau,
I've setup an example similar to yours: Bar Chart - Stacked And Grouped with two plots - JSFiddle .
I did use a data set with a slightly different layout, which I believe is more adequate for this problem. In particular, I used two measure columns:
- year: 2017, 2018
- month: "Jan", "Feb", "Mar", "Apr",
- series: "a", "b"
- num: the number measure
- ratio: the ratio measure
If you can assume that the number of years in the comparison is always two, previous and current, then the chart can be built in a simpler way by using two overlapped stacked bar plots (instead of using a compositeAxis and a two levels category):
- Previous year (2017) — main bar plot uses dataPart=2017 and represents the num measure; bars displaced to the left
- Current year (2018) — second bar plot uses dataPart=2018 and represents the num measure; bars displaced to the right
This achieves the grouped and stacked arrangement of bars while preserving the base axis with the month field alone.
Two line plots can now also be defined to represent the ratio measure. Unfortunately, when the dataPart visual role is used, then all plots must specify a single value, and so two line plots are a necessity as well to cover both years.
Cheers,
Duarte Cunha Leão