admin管理员组文章数量:1333165
I want to display pie legends along with its value in a different format. I am attaching the image. I am looking for it but did not find how to do it till now. If you see the image, legends and the value corresponding to it are shown that i am unable to replicate.
I want to display pie legends along with its value in a different format. I am attaching the image. I am looking for it but did not find how to do it till now. If you see the image, legends and the value corresponding to it are shown that i am unable to replicate.
Share Improve this question asked Apr 23, 2020 at 11:35 user12893845user12893845 1764 silver badges13 bronze badges1 Answer
Reset to default 7You want to display value instead percentages? If yes then this is a little work that need to do because by default legend ponent don't know about another dimensions of you data. Try to start with this code:
var option = {
//...
legend: {
formatter: name => {
var series = myChart.getOption().series[0];
var value = series.data.filter(row => row.name === name)[0].value
return name + ' ' + value;
},
}
}
var myChart = echarts.init(document.getElementById('main'));
var option = {
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b}: {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 10,
data: ['Category1', 'Category2', 'Category3', 'Category4', 'Category5'],
formatter: (name) => {
var series = myChart.getOption().series[0];
var value = series.data.filter(row => row.name === name)[0].value;
return name + ' ' + value;
},
},
series: [
{
name: 'Series',
type: 'pie',
label: { show: false },
labelLine: { show: false },
data: [
{value: 335, name: 'Category1'},
{value: 310, name: 'Category2'},
{value: 234, name: 'Category3'},
{value: 135, name: 'Category4'},
{value: 1548, name: 'Category5'}
]
}
]
};
myChart.setOption(option);
<script src="https://cdn.jsdelivr/npm/[email protected]/dist/echarts.min.js"></script>
<div id="main" style="width: 600px;height:400px;"></div>
本文标签: javascriptEchart configuration for Pie legends in a particular wayStack Overflow
版权声明:本文标题:javascript - Echart configuration for Pie legends in a particular way - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742351934a2458667.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论