Echarts饼状图显示的颜色修改

2022-01-09 09:59:01 浏览数 (1)

指定PIE饼图扇形每个扇面的颜色,修改每个data的ItemStyle对象的color属性即可。{value:235, name:'买衣服',itemStyle: {color: '#9966ff'}}

代码语言:javascript复制
<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8">
        <title>五分钟上手之折线图</title>
        <!-- 引入 echarts.js -->
        <script src="https://cdn.bootcss.com/echarts/4.2.1-rc1/echarts.min.js" type="text/javascript"></script>
        <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
    </head>

    <body>
        <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
        <div id="main" style="width: 600px;height:400px;"></div>
        <script type="text/javascript">
            // 折线图
            $.ajax({
                url: "data.json",
                data: {},
                type: 'GET',
                success: function(data) {
                    /*    alert(JSON.stringify(data))*/

                },
            });

            // 基于准备好的dom,初始化echarts实例
            var myChart = echarts.init(document.getElementById('main'));
            // 指定图表的配置项和数据
            myChart.setOption({
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    x: 'left',
                    data: ['在线', '离线']
                },
                series: [{
                    name: '访问来源',
                    type: 'pie',
                    radius: ['50%', '70%'],
                    avoidLabelOverlap: false,
                    label: {
                        normal: {
                            show: false,
                            position: 'center'
                        },
                        emphasis: {
                            show: true,
                            textStyle: {
                                fontSize: '30',
                                fontWeight: 'bold'
                            }
                        }
                    },
                    labelLine: {
                        normal: {
                            show: false
                        }
                    },
                    data: [
                        { value: 12, name: '在线', itemStyle: { color: '#005eff' } },
                        { value: 3, name: '离线', itemStyle: { color: '#ff9194' } },

                    ]
                }]
            });
        </script>
    </body>

</html>

0 人点赞