Echarts和highCharts圖表使用總結(jié)(附AntV)

Echarts:

1.給y軸上間隔線設(shè)置成虛線

yAxis: {
            type: 'value',
            boundaryGap: [0, '100%'],
            axisLine: {show: false},
            axisTick: {
                show: false //y軸上不顯示刻度
            },
            axisLabel: {           // 坐標軸文本標簽碌嘀,詳見axis.axisLabel
                show: true,
                rotate: 0,
                margin: 20,
                textStyle: {       // 其余屬性默認使用全局文本樣式虏冻,詳見TEXTSTYLE
                    color: 'rgba(0,0,0,0.65)'
                }
            },
            splitLine:{//間隔線
                show:true,
                lineStyle:{
                    type:'dashed',//設(shè)置成虛線
                    color:'#E8E8E8'
                }
            }
        },

2.echarts的x軸和y軸都隱藏

option = {
     xAxis: {
        type: 'category',
        show:false
    },
    yAxis: {
        type: 'value',
        show:false
    },
    series: [{
        symbol: "none",//隱藏折線上的小圓點
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line'
    }]
};

3.設(shè)置圖表的上下間隔線是實線,其余是虛線

   //把xAxis設(shè)為數(shù)組,寫兩個x軸,其余的橫向間隔線在y坐標軸設(shè)置
    xAxis: [{
        type: 'value',
        name: '',
        splitLine: {
            show: false,
        },
       },{
        type: 'category',
       }],
        

4.散點圖中的氣泡圖:標記最大值和做標示線(業(yè)務(wù)需求:篩選出不同類別中最大的那個值并做特殊樣式處理酝掩,比如加個圖片表明是最大值)

series: [{
        markPoint:{//在最大值處加一張圖
            symbol : 'image://./static/img/icon-1/symbols-logo-1.png',
        symbolSize : 10,
        symbolOffset:[0,'-50%'],
            effect : {
                show : true
             },
        label:{
          color:'#FFF',
          fontStyle:14,
          align:'center',
          verticalAlign:'center',
          position: ['50%', '100%']
        },
        data:[{
            name: '最大值',
            type: 'max',
            valueIndex:1
             }],
        },
        markLine:{   //做標記線
                symbol: 'none',
        lineStyle: {
            color: '#5B6DC8',
        },
        label: {
            normal: {
            position: "end",
                backgroundColor: '#101641',
                padding: [10, 20],
                borderRadius: 4,
                color: '#FFF',
                formatter: '',
            },
        },
        animation: false,
        data: [{
            name: 'y軸平均值',
            yAxis: avgY
            },{
            name: 'x軸平均值',
            xAxis: avgX
        }],
         }
    }]

同上:標出最大值(在不同的類別添加標注點眷柔,這種寫法只能在一個類別中添加一個標注點期虾,可以通過在markPoint中的data設(shè)置數(shù)組來添加多個標注點,不過每個標注點的樣式只能相同驯嘱,要想在不同的類別中添加多個標注點且每個標注點樣式不同镶苞,可以用label屬性)

var makeMarkPoint = function (index, url, size, offset, coord) {  
                option.series[index].markPoint = {
                    symbol: 'image://' + url,  //圖片url
                    symbolSize: size,  //設(shè)置標注圖片的大小
                    symbolOffset: offset,  //圖片位置
                    label: {   //標注文字樣式
                        color: '#FFF',
                        fontStyle: 30,
                        align: 'center',
                        verticalAlign: 'middle',
                        position: ['50%', '150%'],
                        formatter: ''
                    },
                    data: [{  //需要進行標注的坐標
                        name: domainDataIndex[index],
                        coord: coord
                    }],
                }
            }
            
makeMarkPoint(index1,'./static/img/top1.png', 40, [0, '-100%'], domainDataCoord[0])
            
var data = [[28604,77,17096869,'11',1990],[31163,77.4,27662440,'22',1990],[1516,68,1154605773,'33',1990]]
    
 //在同一類別下添加多個標注點
    var array1 = [];
    var array2 = [];
    var array3 = [];
    for (var j = 0; j < dataArr.length; j++) { //把數(shù)據(jù)放在一個加入了圖片url的數(shù)組中
        if (max1 == dataArr[j]) {
            datatop3Arr[j].push('./static/img/top1.png');
            array1.push(datatop3Arr[j])
        }
        if (max2 == dataArr[j]) {
            datatop3Arr[j].push('./static/img/top2.png');
            array2.push(datatop3Arr[j])
        }
        if (max3 == dataArr[j]) {
            datatop3Arr[j].push('./static/img/top3.png');
            array3.push(datatop3Arr[j])
        }
    }
    var poptotalarray = [];
    poptotalarray = poptotalarray.concat(array1, array2, array3)

 
    var nameforindex = function (str) {
        if (str == '11') return 0
        if (str == '22') return 1
        if (str == '33') return 2
        if (str == '44') return 3
        if (str == '55') return 4
    }
    var yetaiArray1 = []
    var yetaiArray2 = []
    var yetaiArray3 = []
    var yetaiArray4 = []
    var yetaiArray5 = []
    for (var j = 0; j < poptotalarray.length; j++) {
        var index = nameforindex(poptotalarray[j][4]);
        var pop = {
            name: poptotalarray[j][3],
            coord: [poptotalarray[j][0], poptotalarray[j][1]]
        }
        if (index == 0) yetaiArray1.push(pop);
        if (index == 1) yetaiArray2.push(pop);
        if (index == 2) yetaiArray3.push(pop);
        if (index == 3) yetaiArray4.push(pop);
        if (index == 4) yetaiArray5.push(pop);
    }

用label設(shè)置圖片

(max1,max2,max3為最大的三個值)
    option.series[i].label = {
        show: true,
        position: 'insideTop',//設(shè)置位置在中上
        formatter: function (value) {
            var val = value.data[3];
            var strs = val.split(''); //字符串數(shù)組
            var str = '';
            for (var i = 0, s; s = strs[i++];) { //文本超過三個字就換行
                str += s;
                if (!(i % 3)) str += '\n'; 
            }
            if (parseInt(value.data[2]) == max1) {  
                return [
                    '{topimg1|}',
                    '{value|' + str + '}',
                ].join('\n');
            } else if (parseInt(value.data[2]) == max2) {
                return [
                    '{topimg2|}',
                    '{value2|' + str + '}',
                ].join('\n');
            } else if (parseInt(value.data[2]) == max3) {
                return [
                    '{topimg3|}',
                    '{value3|' + str + '}',
                ].join('\n');
            }
            return ""
        },
        offset: [0, -18],
        textBorderColor: 'transparent',
        rich: {
            value: {
                lineHeight: 15,
                align: 'center',
                color: '#FFF',
                fontWeight: 'bold',
                fontSize: 16,
                padding: [-30, 0, 0, 0]
            },
            value2: {
                lineHeight: 15,
                align: 'center',
                color: '#FFF',
                fontWeight: 'bold',
                fontSize: 14,
                padding: [-20, 0, 0, 0]
            },
            value3: {
                lineHeight: 15,
                align: 'center',
                color: '#FFF',
                fontWeight: 'bold',
                fontSize: 12,
                padding: [-10, 0, 0, 0]
            },
            topimg1: {
                height: 40,
                align: 'center',
                backgroundColor: {
                    image: './static/img/top1.png'
                },

            },
            topimg2: {
                height: 40,
                align: 'center',
                backgroundColor: {
                    image: './img/top2.png'
                },
                width: 30,
                height: 30
            },
            topimg3: {
                height: 40,
                align: 'center',
                backgroundColor: {
                    image: './static/img/top3.png'
                },
                width: 20,
                height: 20
            }
        }
    };

在AntV中給label文字格式化設(shè)置圖片

.label('name', {
    labelLine: false, // 不顯示文本的連接線
    offset: 30, // 文本距離圖形的距離
    htmlTemplate: (text, item, index) => {
      const point = item.point; // 每個弧度對應(yīng)的點
      let percent = point['percent'];
      percent = (percent * 100).toFixed(2) + '%';
      return '<span class="title" style="display: inline-block;width: 50px;">' + text + '</span><br><span style="color:' + point.color + '">' + percent + '</span>'; // 自定義 html 模板
    }
  });

5.標記點設(shè)置成圓環(huán)

    option.series[0].markPoint = { 
                    symbolSize: 15, 
                    symbol: 'circle',
                    itemStyle: {
                        normal: {
                            borderColor: '#45DD54',//環(huán)的顏色
                            color: "#1B235B",//環(huán)內(nèi)的背景色
                            borderWidth: 3, //環(huán)的寬度
                            label: {
                                show: true,
                                backgroundColor: '#45DD54',
                                padding: [6, 20],
                                borderRadius: 4,
                                color: 'white',
                                lineHeight: 20,
                                position: 'top',
                                formatter: '{title|鞠评}\n{num|{c}} %',
                                rich: {
                                    title:{
                                        fontWeight: 'bold',
                                        color: '#fff',
                                        fontSize:16
                                    },
                                    num: {
                                        fontWeight: 'bold',
                                        color: '#fff',
                                        fontSize:20
                                    },

                                }
                            }
                        },
                    },
                    effect: {
                        show: true,
                        shadowBlur: 0
                    },
                    data: [{
                        name: '',
                        value: pointY,
                        xAxis: dateData[20],
                        yAxis: pointY
                    }, ],

                },

6.給標記點設(shè)置背景圖片(適用于背景是對話框有箭頭的樣式)

itemStyle: {
        normal: {
            label: {
                show: true,
                backgroundColor: {
                    image:'./static/img/symbols-up.png',//設(shè)置背景圖
                },
            }
        }
    }   

7.柱狀圖的柱子設(shè)置不同的顏色

series : [
        {
            name:'直接訪問',
            type:'bar',
            barWidth: '60%',
            color: function(val){
                if(val.value == 220){ //位于某個特定值的柱子設(shè)置一個特殊的顏色
                    return "red"  
                }
                return "green";    
            },
            data:[10, 52, 200, 334, 390, 330, 220]
        }
    ]

8.漏斗圖左部分文字左對齊

option = {
    grid: {
        left: 100
    },
    toolbox: {
        show: true,
        feature: {
            saveAsImage: {}
        }
    },
    yAxis: {
        type: 'value',
        axisLabel: {
            formatter: function(a,ix){
                return ix;
            }
        },
        splitLine: {
            lineStyle: {
                type: 'dashed'
            }
        }
    },
    xAxis: {
        show: false
    },
    series: [
        {
            name: 'City Gamma',
            type: 'bar',
            data: [0, 0, 0]
        },
        {
            name: '實際',
            type: 'funnel',
            left: '10%',
            width: '80%',
            maxSize: '80%',
            label: {
                normal: {
                    position: 'inside',
                    formatter: '{c}%',
                    textStyle: {
                        color: '#fff'
                    }
                },
                emphasis: {
                    position:'inside',
                    formatter: '茂蚓實際: {c}%'
                }
            },
            itemStyle: {
                normal: {
                    opacity: 0.5,
                    borderColor: '#fff',
                    borderWidth: 2
                }
            },
            data: [
                {value: 30, name: ''},
                {value: 10, name: ''},
                {value: 5, name: ''},
                {value: 50, name: ''},
                {value: 80, name: ''}
            ]
        }
    ]
};

9.散點圖設(shè)置點均勻分布

是否是脫離 0 值比例。設(shè)置成 true 后坐標刻度不會強制包含零刻度剃幌。在雙數(shù)值軸的散點圖中比較有用聋涨。

{
    scale:true
}

也可以設(shè)置x軸和y軸的最小最大值,達到自己想要的效果

10.設(shè)置echarts圖表隔一段時間刷新

setInterval(function(){
    refresh.call(me);
}, echartsRefreshInterval);

var refresh = function(){
    var div = this.node.root.insertBefore(document.createElement("div"), this.node.echarts);
    $(div).css({
        position: "absolute",
        top: "0",
        left: "0",
        right: "0",
        bottom: "0"
    });
    this.dom.removeDomNode(this.node.echarts);
    this.node.echarts = div;
    this.eChart = echarts.init(this.node.echarts);
    this.eChart.setOption(this.currData, true);
};

11.氣泡圖數(shù)據(jù)多负乡,氣泡重疊在一起的問題

可以統(tǒng)一給所有氣泡x軸的數(shù)據(jù)增加20牍白,幫助分散

12.二級圖例

    <div
        class="item"
        v-for="(item, index) in arr"
        :key="index"
        :class="{ isSelected: index == indexSelected }"
        @click="filter(item, index)"
    >
        <div
          class="item-chunk"
          :style="{ background: `${indexSelected == index && item.isSelect ? item.color : '#999'}` }"
        ></div>
        <div class="item-title">{{ item.title }}</div>
    </div>
filter(code, index) {
      // myChart 的參數(shù)
      code.isSelect = !code.isSelect
      this.indexSelected = index
      var options = this.chartColumn.getOption()
      var selectLegend = options.legend
      for (var i = 0; i < this.arr.length; i++) {
        if (i !== index) this.arr[i].isSelect = false
      }

      for (const key in selectLegend) {
        if (code.isSelect && selectLegend[key].id === code.title) {
          selectLegend[key].show = true
        } else {
          selectLegend[key].show = false
        }
      }
      this.chartColumn.setOption(options, true) // 重新渲染該圖片
    },

highCharts

1.設(shè)置y軸間隔線為虛線

yAxis: {
        gridLineDashStyle: 'ShortDash',//網(wǎng)格線樣式
       },

2.dataLabels線太長導致圖片寬度小時,label自動變省略號看不到

plotOptions: {
    pie: {
        dataLabels: {
            enabled: true,
            format: '{point.name}',
            style: {
                color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                fontSize: '12px',
                fontWeight: 'normal'
            },
            distance:10 //設(shè)置distance改變指示線的長度
        },
        showInLegend: true,
        startAngle: 0, // 圓環(huán)的開始角度
        endAngle: 360,    // 圓環(huán)的結(jié)束角度
        center: ['50%', '50%'],
                size:this.pieSize
    }
},

3.在y軸添加標記線(比如預警線)

plotLines: [
            {
                color: "#BFBFBF",
                dashStyle: "dash",
                width: 1,
                value: 24304,
                label: {
                    useHTML:true,
                    text: "預警線<br/>30萬",
                    align: "right",
                    style: {
                        color: "#919191",
                        fontSize: "10px"
                    },
                    x:10
                },
                zIndex:9999
            }
        ]

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末抖棘,一起剝皮案震驚了整個濱河市茂腥,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌切省,老刑警劉巖最岗,帶你破解...
    沈念sama閱讀 223,207評論 6 521
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異朝捆,居然都是意外死亡仑性,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,455評論 3 400
  • 文/潘曉璐 我一進店門右蹦,熙熙樓的掌柜王于貴愁眉苦臉地迎上來诊杆,“玉大人,你說我怎么就攤上這事何陆〕啃冢” “怎么了?”我有些...
    開封第一講書人閱讀 170,031評論 0 366
  • 文/不壞的土叔 我叫張陵贷盲,是天一觀的道長淘这。 經(jīng)常有香客問我,道長巩剖,這世上最難降的妖魔是什么铝穷? 我笑而不...
    開封第一講書人閱讀 60,334評論 1 300
  • 正文 為了忘掉前任,我火速辦了婚禮佳魔,結(jié)果婚禮上曙聂,老公的妹妹穿的比我還像新娘。我一直安慰自己鞠鲜,他們只是感情好宁脊,可當我...
    茶點故事閱讀 69,322評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著贤姆,像睡著了一般榆苞。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上霞捡,一...
    開封第一講書人閱讀 52,895評論 1 314
  • 那天坐漏,我揣著相機與錄音,去河邊找鬼碧信。 笑死赊琳,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的音婶。 我是一名探鬼主播慨畸,決...
    沈念sama閱讀 41,300評論 3 424
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼衣式!你這毒婦竟也來了寸士?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,264評論 0 277
  • 序言:老撾萬榮一對情侶失蹤碴卧,失蹤者是張志新(化名)和其女友劉穎弱卡,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體住册,經(jīng)...
    沈念sama閱讀 46,784評論 1 321
  • 正文 獨居荒郊野嶺守林人離奇死亡婶博,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,870評論 3 343
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了荧飞。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片凡人。...
    茶點故事閱讀 40,989評論 1 354
  • 序言:一個原本活蹦亂跳的男人離奇死亡名党,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出挠轴,到底是詐尸還是另有隱情传睹,我是刑警寧澤,帶...
    沈念sama閱讀 36,649評論 5 351
  • 正文 年R本政府宣布岸晦,位于F島的核電站欧啤,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏启上。R本人自食惡果不足惜邢隧,卻給世界環(huán)境...
    茶點故事閱讀 42,331評論 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望冈在。 院中可真熱鬧倒慧,春花似錦、人聲如沸讥邻。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,814評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽兴使。三九已至系宜,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間发魄,已是汗流浹背盹牧。 一陣腳步聲響...
    開封第一講書人閱讀 33,940評論 1 275
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留励幼,地道東北人汰寓。 一個月前我還...
    沈念sama閱讀 49,452評論 3 379
  • 正文 我出身青樓,卻偏偏與公主長得像苹粟,于是被迫代替她去往敵國和親有滑。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,995評論 2 361