How does echarts click on the legend to show the broken line and hide the other broken lines?

something like this, but this is done with highcharts, and I now need to modify it on echarts: https://code.hcharts.cn/rench.

Feb.28,2021

Thank you both for your ideas, which have been solved:

var myCharts = echarts.init(document.getElementById("section"));

var triggerAction = function(action, selected) {
  legend = [];

  for (name in selected) {
    if (selected.hasOwnProperty(name)) {
      legend.push({
        name: name
      });
    }
  }

  myCharts.dispatchAction({
    type: action,
    batch: legend
  });
};

//
var isFirstUnSelect = function(selected) {
  var unSelectedCount = 0;
  for (name in selected) {
    if (!selected.hasOwnProperty(name)) {
      continue;
    }

    if (selected[name] == false) {
      unSelectedCountPP;
    }
  }

  return unSelectedCount == 1;
};

//
var onOff = true;

myCharts.on('legendselectchanged', function(obj) {
  var selected = obj.selected;
  var legend = obj.name;
  //  legendToggleSelect Action  legendselectchanged Event
  //   selected 
  if (selected != undefined && isFirstUnSelect(selected) && onOff) {
    triggerAction('legendToggleSelect', selected);
    onOff = false;
  }
});

look at the API in the event section similar to this legendselectchanged


the event selected by the legendselected: example component with the legendSelect legend, that is, when you click to show the legend, the trigger takes effect.

Menu