Echarts條形圖
警戒線主要用markline屬性來實現,參考的官網API地址:http://echarts.baidu.com/api.html#echarts
話不多說直接上圖
這裏主要實現的是添加警戒線,y軸爲雙軸,左側是警戒線的單位,右側是額度的單位
源碼:
var dom1 = " <div id='myChart1' style='width:500px;height:400px;float: left;margin-top: 40px;' ></div>" ;
$('.content').append(dom1);
var myChart = echarts.init(document.getElementById('myChart1'));
option = {
title : {
text: '條形圖',
x:'center',
textStyle:{//標題內容的樣式
color:'#696969',//
fontStyle:'normal',//主標題文字字體風格,默認normal,有italic(斜體),oblique(斜體)
fontWeight:"lighter",//可選normal(正常),bold(加粗),bolder(加粗),lighter(變細),100|200|300|400|500...
fontFamily:"san-serif",//主題文字字體,默認微軟雅黑
fontSize:16//主題文字字體大小
}
},
tooltip: {
trigger: 'axis',
axisPointer : { // 座標軸指示器,座標軸觸發有效
type : 'none' // 默認爲直線,可選爲:'line' | 'shadow'
},
formatter: function(datas)
{
var res = "詳情:" + '<br/>';
res += datas[0].seriesName + ' : ' +initdata+'元 ('+ datas[0].value + '%)'+ '<br/>';
res += '警戒線:'+maxvalue+'%' + '<br/>';
res += datas[1].seriesName + ' : ' + datas[1].value + '元'+ '<br/>';
return res;
}
},
toolbox: {
show : false
},
legend: {
selectedMode:false, //關閉點擊事件
data:['總額度','已使用額度'],
orient: 'vertical',
left: 'left', //圖標放在左邊
},
xAxis: [//設置x軸
{
type: 'category',
data: ['','額度',''],
}
],
yAxis: [//設置y軸
{
type: 'value',
min: 0,
max: 100,
interval: 20,
axisLabel: {
show: true,
interval: 'auto',
formatter: '{value} %'
},
},
{
type: 'value',
splitLine: { show: false },
min: 0,
max: initdata,
formatter: '{value}元'
}
],
series: [
{
name:'總額度',
type:'bar',
data:bardata,//數據
itemStyle: {
normal:{
color: function (params){
var colorList = [
'rgba(70, 130, 180, 0.5)',
'rgba(70, 130, 180, 0.5)',
'rgba(70, 130, 180, 0.5)',
];
return colorList[params.dataIndex];
}
}
},
markLine : {
symbol:"none", //去掉警戒線最後面的箭頭
label:{
position:"end", //將警示值放在哪個位置,三個值“start”,"middle","end" 開始 中點 結束
formatter: "警戒線"
},
data : [{
silent:false, //鼠標懸停事件 true沒有,false有
lineStyle:{ //警戒線的樣式 ,虛實 顏色
type:"solid",
color:"rgba(238, 99, 99)"
},
name: '警戒線',
yAxis: MAXVALUE
}]
}
},
{
name:'已使用額度',
type:'bar',
data:bardata2,//數據
yAxisIndex:1,
itemStyle: {
normal:{
color: function (params){
var colorList = [
'rgba(228, 57, 60, 0.6)',
'rgba(228, 57, 60, 0.6)',
'rgba(228, 57, 60, 0.6)',
];
return colorList[params.dataIndex];
}
}
}
}
]
};
// 使用剛指定的配置項和數據顯示圖表。
myChart.setOption(option);
Echarts中,實現雙軸,主要是兩個地方配置,第一個在yAxis中配置,第二個在series中配置,
實現markline,在相對應的series中,配置markline屬性,Label來調控標籤顯示的位置以及樣式