如何在echarts条形图中手动强调系列?

How to manually apply emphasis on series in echarts bar-graph?

我有一个包含一系列数据的 echarts 条形图。单击某个栏时,会对其应用强调。有没有办法以编程方式 select 条形图中的一个系列来强调图表加载的时间?

条形图的选项代码:

  options = {
    markPoint: { data: ['Q1'] },
    color: ['#3398DB'],
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      }
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        data: ['Q1', 'Q2', 'Q3', 'Q4'],
        axisTick: {
          alignWithLabel: true,
        }
      }
    ],
    yAxis: [{
      type: 'value'
    }],
    series: [{
      name: 'Counters',
      type: 'bar',
      barWidth: '50%',
      data: [3,8,12,5],
      itemStyle: {
        //highlight
        emphasis: {
          barBorderColor: 'red',
          barBorderWidth: 2
        }

      }
    }]
  };

谢谢。

是的,很简单。 Echarts API 有两种动作相反的方法:

一个小例子:

  var myChart = echarts.init(document.getElementById('main'));
    var chartData = [5, 20, 36, 10, 10, 20];

  var option = {
    tooltip: {},
    legend: {
      data: ['Label']
    },
    xAxis: {
      data: ["Category1", "Category2", "Category3", "Category4", "Category5", "Category6"]
    },
    yAxis: {},
    series: [{
      name: 'Series',
      type: 'bar',
      data: chartData,
            emphasis: {
                itemStyle: {
                    color: 'blue'
                }
            },
    }]
  };

  myChart.setOption(option);
    
    // Current selected dataPoint
    var selectedDataPoint = null;
    
    // Each eteration set another type of 
    setInterval(() => {
        var randomDataPoint = Math.floor(Math.random() * Math.floor(chartData.length));
        myChart.dispatchAction({ type: 'highlight', dataIndex: randomDataPoint })
    }, 800)
    
<script src="https://cdn.jsdelivr.net/npm/echarts@4.8.0/dist/echarts.min.js"></script>
<div id="main" style="width: 600px;height:400px;"></div>