stevenjin 2023-11-14 11:35 采纳率: 97.6%
浏览 10
已结题

echart 双x轴怎样动态赋值

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);

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-11-14 15:25
    关注

    【相关推荐】




    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月26日
  • 已采纳回答 11月18日
  • 修改了问题 11月14日
  • 创建了问题 11月14日

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向