var yAxisIndexData = [0,50,125,250,400];
var data1 = [41.1, 86.5, 300];
var data2 = [30.4, 150, 67.2];
var data1New = [41.1, 86.5, 300];
var data2New = [30.4, 150, 67.2];
function addYValueFn(value) {
if (value <= yAxisIndexData[1]) {
value = 4/yAxisIndexData[1] * value;
} else if (value > yAxisIndexData[1] && value <= yAxisIndexData[2]) {
value = 4 + 2/(yAxisIndexData[2] - yAxisIndexData[1]) * (value - yAxisIndexData[1]);
} else if (value > yAxisIndexData[2] && value <= yAxisIndexData[3]) {
value = 6 + 2/(yAxisIndexData[3] - yAxisIndexData[2]) * (value - yAxisIndexData[2]);
} else {
value = 8 + 2/(yAxisIndexData[4] - yAxisIndexData[3]) * (value - yAxisIndexData[3]);
}
return value;
};
data1New = data1New.map(function(item) {
return addYValueFn(item);
});
data2New = data2New.map(function(item) {
return addYValueFn(item);
});
option = {
color: [’#2A95E3’, ‘#E59042’],
legend: {},
tooltip : { // 悬浮窗
trigger : ‘axis’,
formatter: function (params, ticket, callback) {
console.log(params);
console.log(ticket);
var zbName = ‘’;
if (params.length > 0) {
var showHtml = “”;
showHtml += params[0].name + ‘
’;
for (var i = 0; i < params.length; i++) {
showHtml += ‘’ + params[i].seriesName + ‘:’ + params[i].data[2] + ‘
’;
}
return showHtml;
} else {
return ‘’;
}
}
},
xAxis: [
{
type: ‘category’,
gridIndex: 0,
data: [‘参数1’, ‘参数2’, ‘参数3’]
}
],
yAxis: [
{
type: ‘value’,
scale: true,
min: 0,
max: 10,
axisLine: {
symbol: [‘none’, ‘arrow’]
},
splitLine: {
show: false
},
axisLabel : {
formatter : function(value) { // 格式化y轴的坐标展示
var texts = [];
if (value == 4) {
texts.push(yAxisIndexData[1]);
} else if (value == 6) {
texts.push(yAxisIndexData[2]);
} else if (value == 8) {
texts.push(yAxisIndexData[3]);
} else if (value == 10) {
texts.push(yAxisIndexData[4]);
} else if (value === 0) {
texts.push(yAxisIndexData[0]);
}
return texts;
}
},
}
],
series: [
{
name: ‘#8’,
type: ‘bar’,
data: [[0, data1New[0], data1[0]], [1, data1New[1], data1[1]], [2, data1New[2], data1[2]]],
itemStyle: {
color: new echarts.graphic.LinearGradient(
0, 0, 0, 1,
[
{offset: 0, color: ‘#3AE5E0’},
{offset: 0.5, color: ‘#33C1E2’},
{offset: 1, color: ‘#188df0’}
]
)
},
barWidth: 20
},
{
name: ‘#9’,
type: ‘bar’,
data: [[0, data2New[0], data2[0]], [1, data2New[1], data2[1]], [2, data2New[2], data2[2]]],
itemStyle: {
color: new echarts.graphic.LinearGradient(
0, 0, 0, 1,
[
{offset: 0, color: ‘#F8BF47’},
{offset: 0.5, color: ‘#F1AD45’},
{offset: 1, color: ‘#E38A42’}
]
)
},
barWidth: 20
},
]
};