html5 - echarts legend
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 13:37:59
0
1
435

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!

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(1)
習慣沉默
    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
        }]

    });
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!