echart中需要实时显示双x轴数据,”方法一“无法对另一条x轴赋值,即下面这个写死的,要怎样把对另一个x轴写成动态:
"data: ['2021-1轮', '2021-2轮', '2021-3轮']"
方法一
setInterval(function () {
data_Temp.push(GetData());
myChart .setOption({
yAxis: {
max: upRange,
min: lowRange, // 最小值
type: 'value'
},
series: [{
data: data_Temp
}]
}, false);
}, 1000);
示例
var myChart = echarts.init(document.getElementById('allOutPut1'));
var option = {
legend: {
itemHeight: 10, // 图例icon高度
itemWidth: 16, // 图例icon宽度
icon:'rect',//设置为矩形
top:'2%',right:'10%',
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
},
textStyle: {
fontSize: 12
},
},
grid: { top: '10%',bottom: '28%' },
xAxis: [
{
type: 'category',
axisTick:{
show: false
},
axisLine:{
show: false
},axisLabel:{align:'center'},
data: ['水分', '酸度', '淀粉','水分', '酸度', '淀粉','水分', '酸度', '淀粉']
},
{
type: 'category',
position: 'bottom',
offset: 18,
axisPointer: {
type: 'none'
},
axisTick:{
show: false
},
axisLine:{
show: false
},
axisLabel: {
interval:0,align: 'center'
},
splitLine: { // 新增代码,设置分隔线样式
show: true,
lineStyle: {
type: 'dashed',
color: '#999',
width: 1
}
},
data: ['2021-1轮', '2021-2轮', '2021-3轮']
}
],
yAxis: {name:'%',
type: 'value',
},
series: [
{
name: '低于工艺范围',
type: 'bar',barWidth:'9%',xAxisIndex:0,
color: '#569EF8',
showBackground: true,
backgroundStyle: {
color: 'rgba(255, 255, 255, 0.5)'
},
itemStyle: {
// 柱形图圆角,鼠标移上去效果,如果只是一个数字则说明四个参数全部设置为那么多
normal: {
// 柱形图圆角,初始化效果
barBorderRadius: [15, 15, 0, 0]
}
},
data: [113, 204, 210,113, 204, 210,113, 204, 210]
},
{
name: '工艺要求范围',
type: 'bar',barWidth:'9%',xAxisIndex:0,
color:'#00FEC1',
showBackground: true,
backgroundStyle: {
color: 'rgba(255, 255, 255, 0.5)'
},
itemStyle: {
// 柱形图圆角,鼠标移上去效果,如果只是一个数字则说明四个参数全部设置为那么多
normal: {
// 柱形图圆角,初始化效果
barBorderRadius: [15, 15, 0, 0]
}
},
data: [193, 234, 310,193, 234, 310,193, 234, 310]
},
{
name: '超出工艺范围',
type: 'bar',barWidth:'9%',xAxisIndex:0,
color:'#F3D46C',
showBackground: true,
backgroundStyle: {
color: 'rgba(255, 255, 255, 0.5)'
},
itemStyle: {
// 柱形图圆角,鼠标移上去效果,如果只是一个数字则说明四个参数全部设置为那么多
normal: {
// 柱形图圆角,初始化效果
barBorderRadius: [15, 15, 0, 0]
}
},
data: [182, 234, 290,182, 234, 290,182, 234, 290]
},
],
dataZoom: [//给x轴设置滚动条
{
start:0,//默认为0
end: 100,//默认为100
type: 'slider',
show: true,
xAxisIndex: [0,1],
handleSize: 0,//滑动条的 左右2个滑动条的大小
height: 5,//组件高度
left: 30, //左边的距离
right: 60,//右边的距离
bottom: 25,//右边的距离
handleColor: '#ddd',//h滑动图标的颜色
handleStyle: {
borderColor: "#cacaca",
borderWidth: "1",
shadowBlur: 2,
background: "#ddd",
shadowColor: "#ddd",
},
fillerColor: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
//给颜色设置渐变色 前面4个参数,给第一个设置1,第四个设置0 ,就是水平渐变
//给第一个设置0,第四个设置1,就是垂直渐变
offset: 0,
color: '#E6E6E6'
}, {
offset: 1,
color: '#E6E6E6'
}]),
backgroundColor: '#F8F8F8',//两边未选中的滑动条区域的颜色
showDataShadow: false,//是否显示数据阴影 默认auto
showDetail: false,//即拖拽时候是否显示详细数值信息 默认true
handleIcon: 'M-292,322.2c-3.2,0-6.4-0.6-9.3-1.9c-2.9-1.2-5.4-2.9-7.6-5.1s-3.9-4.8-5.1-7.6c-1.3-3-1.9-6.1-1.9-9.3c0-3.2,0.6-6.4,1.9-9.3c1.2-2.9,2.9-5.4,5.1-7.6s4.8-3.9,7.6-5.1c3-1.3,6.1-1.9,9.3-1.9c3.2,0,6.4,0.6,9.3,1.9c2.9,1.2,5.4,2.9,7.6,5.1s3.9,4.8,5.1,7.6c1.3,3,1.9,6.1,1.9,9.3c0,3.2-0.6,6.4-1.9,9.3c-1.2,2.9-2.9,5.4-5.1,7.6s-4.8,3.9-7.6,5.1C-285.6,321.5-288.8,322.2-292,322.2z',
filterMode: 'filter',
},
//下面这个属性是里面拖到
{
type: 'inside',
show: true,
xAxisIndex: [0],
start: 0,//默认为1
end: 100,//默认为100
},
]
}
// 使用刚指定的配置项和数据显示图表
myChart.setOption(option);