Echarts餅狀圖標題位置的設置

Echarts餅狀圖標題位置一開始默認是在左上方,根據須要,echarts餅圖標題如何顯示在餅圖右下方 ?只須要修改legend裏面的xy屬性便可:javascript

legend: {
                    orient: 'vertical',
                     x:'right',
                     y: 'bottom',
                    data: ['在線', '離線']
                },

寫一個具體的demo:css

<!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: 300px;height:300px;"></div>
        <script type="text/javascript">
            // 基於準備好的dom,初始化echarts實例
            var myChart = echarts.init(document.getElementById('main'));
            // 指定圖表的配置項和數據
            myChart.setOption({
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                      x:'right',
                     y: 'bottom',
                    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>

效果以下所示:html

 
5640239-ca7e6b3e97568929.png
 

原文做者:祈澈姑娘 
90後前端妹子,愛編程,愛運營,文藝與代碼齊飛,魅力與智慧共存的程序媛一枚前端

相關文章
相關標籤/搜索