Define multiple series from dataset
See original GitHub issueWhat problem does this feature solve?
I am not sure if this is possible at the moment, but I haven’t been able to find it in documentation and these Stack Overflow questions lead me to believe it’s not solved: https://stackoverflow.com/questions/69215766/echarts-separate-series-based-on-dataset-field https://stackoverflow.com/questions/65847643/how-to-display-multiple-lines-in-echarts-using-encode
This feature would allow you to pass in a single dataset and create multiple series from that dataset without having to transform, filter, or loop through the dataset. This is important for data stored in ‘tidy’ format, where one column contains the group that should be used to create the multiple series. This is a common data format for people using a data warehouse.
There are two workarounds I’ve found so far, but neither is ideal:
- Use VisualMap piecewise categories, but this is not ideal because the legend is different than the normal series legend, and setting this up is confusing
- Loop through the dataset and filter for each distinct item in the column containing the group names, then create a series for each
It seems like this might be the solution to this problem? https://github.com/apache/echarts/pull/15747
I’ve added some sample code below showing an additional option in encode
, but it probably shouldn’t belong in series
since that represents a single series.
What does the proposed API look like?
option = {
dataset: {
source:
[
{group: "A", product: 'Matcha Latte', count: 823, score: 95.8},
{group: "A", product: 'Milk Tea', count: 235, score: 81.4},
{group: "A", product: 'Cheese Cocoa', count: 1042, score: 91.2},
{group: "A", product: 'Walnut Brownie', count: 988, score: 76.9},
{group: "B", product: 'Matcha Latte', count: 23, score: 95.8},
{group: "B", product: 'Milk Tea', count: 25, score: 81.4},
{group: "B", product: 'Cheese Cocoa', count: 142, score: 91.2},
{group: "B", product: 'Walnut Brownie', count: 98, score: 76.9}
]
},
xAxis: {
type: 'category'
},
yAxis: {
type: 'value'
},
series: [
{
type: 'bar',
encode:
{
x: 'product',
y: 'count',
series: 'group'
}
}
]
};
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
I don’t think this is possible without defining multiple series. You may use dataset filter to create multiple dataset instance for different series to use.
Thanks - I’ll write some logic to define each series individually