'Echarts pie with dataset
I want draw a pie like this, and I want to store data in dataset
:
option = {
dataset: {
dimensions: ['a', 'b'],
source: { a: 85, b: 79 }
},
series: [
{
name: 'template',
type: 'pie',
// get data from dataset
}
]
};
source
is an object, so I can just reset the dataset when source
was changed and dont need to do likeoption.series[0].data[0].value = ...
for every value.
I was try to set encode.value = ['a', 'b']
or some other settings but it was not work. How can I do for this?
Solution 1:[1]
The source format of your dataset should be one of these 3 formats :
source: [
{name: 'a', value: 85},
{name: 'b', value: 79},
]
source: [
['name', 'value'],
['a', 85],
['b',79]
]
source: {
'name': ['a', 'b'],
'value': [85, 79],
}
For example :
var myChart = echarts.init(document.getElementById('main'));
option = {
dataset: {
source: [
{name: 'a', value: 85},
{name: 'b', value: 79},
]
},
series: [
{
name: 'template',
type: 'pie',
}
]
};
myChart .setOption(option)
<html>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.3.2/echarts.min.js"></script>
<div id="main" style="width: 600px; height:400px;"></div>
</body>
</html>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | A mere dev |