1. 程式人生 > 其它 >Echarts製作橫向座標軸,並且文字名稱和數值都在橫向座標軸的上面

Echarts製作橫向座標軸,並且文字名稱和數值都在橫向座標軸的上面

技術標籤:大前端jsechartshtml5

參考下面Deno
https://www.makeapie.com/editor.html?c=xgNHRfHRfA

var  getmydmc=['數學','語文','英語'];//資料點名稱
var  getmyd=[86.25,90.26,77.88];//學生滿意度
var getmydzd =[];//學生滿意度100%
for (let i = 0; i < getmyd.length; i++) {
    getmydzd.push(100)
}

option = {
    grid: {
        show:true,
        width:
300, height:350, left: '170', right: '75', bottom: '3%', top: '3%', }, tooltip: { trigger: 'axis', axisPointer: { type: 'none' }, formatter: function(params) { return '及格率<br>'+ params[0].name +
': ' + params[0].value+'%' } }, xAxis: { show: false, type: 'value' }, yAxis: [{ type: 'category', inverse: true, axisLabel: { textStyle: { color: '#666666', fontSize: '14', lineHeight:
20, }, // 調整左側文字的3個屬性,缺一不可 verticalAlign: 'bottom', align:'right', //調整文字上右下左 padding: [0,-80,15,0], }, splitLine: { show: false }, axisTick: { show: false }, axisLine: { show: false }, data: getmydmc }, { type: 'category', inverse: true, axisTick: 'none', axisLine: 'none', show: true, axisLabel: { textStyle: { color: '#333333', fontSize: '14' }, // 調整右側數值文字的3個屬性,缺一不可 padding: [0, 0, 35, -130], formatter: '{value}%' }, data:getmyd }], series: [{ name: '值', type: 'bar', zlevel: 1, itemStyle: { normal: { barBorderRadius: 5, color: '#4E7BFE' }, }, barWidth: 15, data: getmyd }, { name: '背景', type: 'bar', barWidth: 15, barGap: '-100%', data: getmydzd, itemStyle: { normal: { color: 'rgba(103,150,253,0.3)', barBorderRadius: 5, } }, }, ] };

效果圖如下:
在這裡插入圖片描述