echarts雷達圖大小自適應


結合了媒體查詢

首先在css樣式表中寫出你希望雷達圖在不同分辨率下的大小

@media screen and (max-height:780px){
    .left-score-image {
        width: 190px;
        height: 135px;
        margin-left: 36px;
        margin-top: 10px;
    }
}

其次,在js文件中加入

var scoreImage = document.getElementById('scoreImage');
        var myChart = echarts.init(scoreImage);
        function test() {       
            myChart.setOption({
                title: { text:null }, // 隱藏圖表標題
                legend: { enabled: false }, // 隱藏圖例
                tooltip : {
                    trigger: 'axis'
                },
                grid: { // 控制圖的大小,調整下面這些值就可以,
                    x: 40,
                    x2: 100,
                    y2: 150// y2可以控制 X軸跟Zoom控件之間的間隔,避免以為傾斜后造成 label重疊到zoom上
                },
                calculable : true,
                polar : [
                    {
                        nameGap : 5, // 圖中工藝等字距離圖的距離
                        splitNumber: 4, // 網格線的個數
                        center:['50%','50%'], // 圖的位置
                        name:{
                           show: true, // 是否顯示工藝等文字
                           formatter: null, // 工藝等文字的顯示形式
                           textStyle: {
                             color:'#a3a5b6' // 工藝等文字顏色
                           }
                         },
                        indicator : [
                            {text : '結構原理', max  : 100},
                            {text : '機組檢修', max  : 100},
                            {text : '機組試車', max  : 100},
                            {text : '機組操作', max  : 100},
                            {text : '日常維護', max  : 100},
                            {text : '異常處置', max  : 100}
                        ],
                        axisLine: {            // 坐標軸線
                            show: true,        // 默認顯示,屬性show控制顯示與否
                            lineStyle: {       // 屬性lineStyle控制線條樣式
                                color: '#1e6db3',
                                width: 1,
                                type: 'solid'
                            }
                        },
                        axisLabel: {           // 坐標軸文本標簽,詳見axis.axisLabel
                            show: false,
                            /*formatter: function (value){
                                return "星期" + "日一二三四五六".charAt(value);
                            },*/
                            interval: 3,
                            textStyle: {       
                                color: '#247bd7', // 坐標軸刻度文字的樣式
                                fontSize : "10px" 
                            }
                        },
                        splitArea : {
                            show : true,    
                            areaStyle : {
                                color: ["#17365d"]  // 圖表背景網格的顏色
                            }
                        },
                        splitLine : {
                            show : true,
                            lineStyle : {
                                width : 1,
                                color : '#286fbb' // 圖表背景網格線的顏色
                            }
                        }
                    }
                ],
                series : [
                    {
                        name: '完全實況球員數據', 
                        type: 'radar',
                        symbol: "none", // 去掉圖表中各個圖區域的邊框線拐點
                        itemStyle: {
                            normal: {
                                lineStyle: {
                                    color:"rgba(255,255,255,0.5)" // 圖表中各個圖區域的邊框線顏色
                                },
                                areaStyle: {
                                    type: 'default'
                                }
                            }
                        },
                        data : [
                            {
                                value : [50, 42, 88, 60, 90],
                                itemStyle: {
                                    normal: {
                                        areaStyle: {
                                            type: 'default',
                                            opacity: 0.6, // 圖表中各個圖區域的透明度
                                            color: "#1686c2" // 圖表中各個圖區域的顏色
                                        }
                                    }
                                },
                                name : '重整'
                            },
                            {
                                value : [90, 32, 74, 20, 60],
                                itemStyle: {
                                    normal: {
                                        areaStyle: {
                                            type: 'default',
                                            opacity: 0.6,
                                            color: "#6eaf97" // 圖表中各個圖區域的顏色
                                        }
                                    }
                                },
                                name : '催化'
                            }
                        ]
                    }
                ]
            }); 
        }
        test();
        $(window).resize(function() {//這是能夠讓圖表自適應的代碼
            myChart.resize();
        });  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM