search

Home  >  Q&A  >  body text

html5 - echarts legend

As shown in the figure, I want to directly obtain the name of each segment of the pie chart in the background and use it as the legend directly, replacing the red "test" at the top. How to get the name of each segment? Thanks!

曾经蜡笔没有小新曾经蜡笔没有小新2819 days ago478

reply all(1)I'll reply

  • 習慣沉默

    習慣沉默2017-05-16 13:39:59

        var myChart = echarts.init(document.getElementById('main')),
            option = {
                tooltip: {},
                legend: {},
                series: [{
                    name: '访问来源',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '60%'],
                    data: [],
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }]
            };
        myChart.setOption(option);
    
        //以下为ajax获取到的数据
        var data = [{
                value: 335,
                name: '直接访问'
            }, {
                value: 310,
                name: '邮件营销'
            }, {
                value: 234,
                name: '联盟广告'
            }, {
                value: 135,
                name: '视频广告'
            }, {
                value: 1548,
                name: '搜索引擎'
            }],
            legends = []
        data.forEach(function(e, i) {
            legends.push(e.name)
        })
        myChart.setOption({
            legend: {
                data: legends
            },
            series: [{
                data: data
            }]
    
        });

    reply
    0
  • Cancelreply