Mixed Bar/Line Chart
As we have seen, chart can have multiple datasets. Each dataset can also have a different chartType
.
data: {
labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
datasets: [
{
name: "Dataset 1",
values: [18, 40, 30, 35, 8, 52, 17, -4],
chartType: 'bar'
},
{
name: "Dataset 2",
values: [30, 50, -10, 15, 18, 32, 27, 14],
chartType: 'line'
}
]
},
This allows for creation of mixed axis chart. It is recommended to list the bar datasets before the line ones to avoid overlapping.
All the lineOptions
and barOptions
apply to mix and match datasets as well.
Infact, one of the bar options is actually dependent on multiple datasets.
Stacked Bar Chart
Unlike lines, bars have two ways to show multiple data point values: adjacent or stacked bars. Stacked bar charts are similar to area charts, being useful for comparisions of similar trends. The property stacked
in barOptions
renders a stacked bar chart instead of the default adjacent bars:
barOptions: {
stacked: 1; // default 0, i.e. adjacent
}
In Aggregation Charts however, instead of being rendered individually, each data point in aggregated accross every dataset. We'll cover those next.