解決echarts 一條柱狀圖顯示兩個(gè)值,類似進(jìn)度條的問(wèn)題
我就廢話不多說(shuō)說(shuō)了,大家還是直接看代碼吧~
var allUseDayChartTwo;
function allUseDayChartTwoFun(obj,xdata,ydata,zdata){
allUseDayChartTwo = echarts.init(obj);
var category = xdata;
var lineData = zdata;
var barData = ydata;
option = {
// backgroundColor:'#F00',
tooltip: {
trigger: 'axis',
backgroundColor:'rgba(0,0,0,.5)',
axisPointer: {
type: 'shadow',
label: {
show: true,
backgroundColor: '#F1F1F1',
color:'#5A5A5A'
}
},
confine: true
},
grid: {
left: '1%',
right: '3%',
bottom: '5%',
top: '5%',
containLabel: true
},
xAxis: {
axisLine: {
lineStyle: {
color: '#B4B4B4'
}
},
axisTick:{
show:false,
},
axisLine:{
show:false
},
axisTick:{
show:false
},
splitLine:{
show:false
},
axisLabel:{
textStyle: {
fontSize: 14,
},
formatter:'{value} ',
},
},
yAxis: [{
data: category,
splitLine: {show: false},
axisLine: {
lineStyle: {
color: '#B4B4B4',
}
},
axisLabel:{
textStyle: {
fontSize: 14,
// color: '#B2B2B2'
},
formatter:'{value} ',
},
axisLine:{
show:false
},
axisTick:{
show:false
},
splitLine:{
show:false
}
}
// ,{
// data: category,
// splitLine: {show: false},
// axisLine: {
// lineStyle: {
// color: '#B4B4B4',
// }
// },
// axisLabel:{
// formatter:'{value} ',
// }
// }
],
series: [{
name: '用量',
type: 'bar',
barWidth: 15,
barGap: '-100%',
itemStyle: {
normal: {
barBorderRadius: 5,
color: new echarts.graphic.LinearGradient(
0, 0, 0, 1,
[
{offset: 0, color: 'rgba(88,228,88,0.8)'},
{offset: 1, color: 'rgba(88,228,88,0.8)'}
]
)
}
},
data: barData
},{
name: '閾值',
type: 'bar',
barGap: '-100%',
barWidth: 15,
itemStyle: {
normal: {
barBorderRadius: 5,
color: new echarts.graphic.LinearGradient(
0, 0, 0, 1,
[
{offset: 0, color: 'rgba(234,234,234,0.8)'},
{offset: 0.2, color: 'rgba(234,234,234,1)'},
{offset: 1, color: 'rgba(234,234,234,1)'}
]
)
}
},
z: -12,
data: lineData
}
// ,{
// name: '背景',
// type: 'bar',
// barGap: '-100%',
// barWidth: 15,
// itemStyle: {
// normal: {
// barBorderRadius: 5,
// color: new echarts.graphic.LinearGradient(
// 0, 0, 0, 1,
// [
// {offset: 0, color: 'rgba(0,0,0,0.2)'},
// {offset: 0.2, color: 'rgba(0,0,0,0.)'},
// {offset: 1, color: 'rgba(0,0,0,0.24)'}
// ]
// )
// }
// },
// z: -20,
// data: [50,50,50,50,50,50,50,50,50]
// }
]
};
allUseDayChartTwo.setOption(option);
}

補(bǔ)充知識(shí):echarts 柱狀圖實(shí)現(xiàn)進(jìn)度條,進(jìn)行數(shù)據(jù)驅(qū)動(dòng)
echarts 柱狀圖實(shí)現(xiàn)進(jìn)度條,進(jìn)行數(shù)據(jù)驅(qū)動(dòng)
效果圖

直接寫上配置項(xiàng),根據(jù)自己的需求更改
option = {
backgroundColor: '#0a1d53',
grid: {
left: '2%',
top: '2%',
right: '2%',
bottom: '2%',
containLabel: true
},
tooltip: {
trigger: 'item',
axisPointer: {
// 坐標(biāo)軸指示器,坐標(biāo)軸觸發(fā)有效
type: 'shadow' // 默認(rèn)為直線,可選為:'line' | 'shadow'
}
},
textStyle: {
color: '#fff'
},
xAxis: {
show: false,
type: 'value',
// 設(shè)置x軸顯示幾段
min: 0,
max: 100,
inverse: true,
splitLine: {
show: false
},
interval: 50
},
yAxis: {
show: true,
type: 'category',
data: [
'周一',
'周二',
'周三',
'周五',
'周五',
'周六',
'周日'
],
axisTick: { show: false },
axisLine: {
show: false,
lineStyle: {
color: 'red'
}
},
splitLine: {
show: false
},
inside: true,
textStyle: {
color: '#000c45'
}
},
series: [
{
type: 'bar',
itemStyle: {
normal: {
color: '#000c45', // 定義柱形的背景色
barBorderRadius: [5, 5, 5, 5] // 定義背景柱形的圓角
}
},
barGap: '-100%', // 設(shè)置柱形重合的重要步驟
data: [100, 100, 100, 100, 100, 100, 100],
z: 0,
silent: true,
animation: false, // 關(guān)閉動(dòng)畫效果
barWidth: '10px' // 設(shè)置柱形寬度
},
{
type: 'bar',
data: [50, 50, 50, 50, 50,50, 50],
barWidth: '10px',
barGap: '-100%', // 設(shè)置柱形重合的重要步驟
label: {
normal: {
show: true, //是否顯現(xiàn),不顯示的話設(shè)置成false
position: "left", //顯示的位置
distance: 10, //距離侄子的值 // label要顯示的值比如: 20%
formatter: function(param) {
return param.value;
},
textStyle: {
//這個(gè)地方顏色是支持回調(diào)函數(shù)的這種的,如果是一種顏色則可以寫成: color :'#1089E7'
color: function(params) {
var num = myColor.length; //得到myColor顏色數(shù)組的長(zhǎng)度
return myColor[params.dataIndex % num]; //返回顏色數(shù)組中的一個(gè)對(duì)應(yīng)的顏色值
},
fontSize: "16"
}
}
},
itemStyle: {
normal: {
color: function (params) {
var colorList = [
'#bbb743',
'#bbae43',
'#bb9d43',
'#bb8c43',
'#bb7e43',
'#bb5c43',
'#bb4643'
]
return colorList[params.dataIndex]
},
barBorderRadius: [5, 5, 5, 5] // 定義柱形的圓角
}
}
}
]
}
以上這篇解決echarts 一條柱狀圖顯示兩個(gè)值,類似進(jìn)度條的問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- Echarts基本入門之柱狀圖、折線圖通用配置
- Echarts Bar橫向柱狀圖實(shí)例代碼
- Vue使用Echarts實(shí)現(xiàn)立體柱狀圖
- vue echarts實(shí)現(xiàn)柱狀圖動(dòng)態(tài)展示
- vue echarts實(shí)現(xiàn)橫向柱狀圖
- uniapp引用echarts的詳細(xì)步驟(附柱狀圖實(shí)例)
- echarts動(dòng)態(tài)渲染柱狀圖背景顏色及頂部數(shù)值方法詳解
- 基于vue+echarts實(shí)現(xiàn)柱狀圖漸變色效果(每個(gè)柱子顏色不同)
- Echarts柱狀圖修改柱子顏色漸變及柱子圓角效果實(shí)例
相關(guān)文章
vue使用自定義指令來(lái)控制頁(yè)面按鈕組的權(quán)限思想
這篇文章主要介紹了vue使用自定義指令來(lái)控制頁(yè)面按鈕組的權(quán)限思想,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
vue項(xiàng)目打包后瀏覽器緩存問(wèn)題及解決
這篇文章主要介紹了vue項(xiàng)目打包后瀏覽器緩存問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03
vue項(xiàng)目中自動(dòng)導(dǎo)入svg并愉快的使用方式
這篇文章主要介紹了vue項(xiàng)目中自動(dòng)導(dǎo)入svg并愉快的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11

