• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

echart的brush,设置柱状图工具栏brush和区域选择触发事件brushSelected,数据变化选区域自动触发更新

武飞扬头像
aliven1
帮助1

let xAxisData = [];
let data1 = [];
let data2 = [];
let data3 = [];
let data4 = [];
for (let i = 0; i < 10; i  ) {
  xAxisData.push('Class'   i);
  data1.push( (Math.random() * 2).toFixed(2));
  data2.push( (Math.random() * 5).toFixed(2));
  data3.push( (Math.random()   0.3).toFixed(2));
  data4.push( Math.random().toFixed(2));
}
var emphasisStyle = {
  itemStyle: {
    shadowBlur: 10,
    shadowColor: 'rgba(0,0,0,0.3)'
  }
};
option = {
  legend: {
    data: ['bar', 'bar2', 'bar3', 'bar4'],
    left: '10%'
  },
  brush: {
    toolbox: ['rect', 'polygon', 'lineX', 'lineY', 'keep', 'clear'],
    xAxisIndex: 0
  },
  toolbox: {
    feature: {
      magicType: {
        type: ['stack']
      },
      dataView: {}
    }
  },
  tooltip: {},
  xAxis: {
    data: xAxisData,
    name: 'X Axis',
    axisLine: { onZero: true },
    splitLine: { show: false },
    splitArea: { show: false }
  },
  yAxis: {},
  grid: {
    bottom: 100
  },
  series: [
    {
      name: 'bar',
      type: 'bar',
      stack: 'one',
      emphasis: emphasisStyle,
      data: data1
    },
    {
      name: 'bar2',
      type: 'bar',
      stack: 'one',
      emphasis: emphasisStyle,
      data: data2
    },
    {
      name: 'bar3',
      type: 'bar',
      stack: 'two',
      emphasis: emphasisStyle,
      data: data3
    },
    {
      name: 'bar4',
      type: 'bar',
      stack: 'two',
      emphasis: emphasisStyle,
      data: data4
    }
  ]
};
myChart.on('brushSelected', function (params) {
  var brushed = [];
  var brushComponent = params.batch[0];
  for (var sIdx = 0; sIdx < brushComponent.selected.length; sIdx  ) {
    var rawIndices = brushComponent.selected[sIdx].dataIndex;
    brushed.push('[Series '   sIdx   '] '   rawIndices.join(', '));
  }
  myChart.setOption({
    title: {
      backgroundColor: 'red',
      text: 'SELECTED DATA INDICES: \n'   brushed.join('\n'),
      bottom: 0,
      right: '10%',
      width: 100,
      textStyle: {
        fontSize: 12,
        color: '#fff'
      }
    }
  });
});
学新通

学新通

设置柱状图工具栏配置

brush: {
toolbox: [‘rect’, ‘polygon’, ‘lineX’, ‘lineY’, ‘keep’, ‘clear’],
xAxisIndex: 0
}

区域选择触发事件brushSelected

数据变化选中区域自动触发更新

可解决数据动态刷新,展示数据同步更新,滚轮缩放,滑块拖动展示等问题

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhghacik
系列文章
更多 icon
同类精品
更多 icon
继续加载