最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ECharts js - Custom HTML Legend - Stack Overflow

programmeradmin6浏览0评论

I have created a pie chart using ECharts. Thus, I would like to use a custom HTML for my legend but I don't know how to use their events.

Here is a fiddle of what I've done so far: /

I don't know the right function/event to make my custom legend clickable so I can show/hide the selected data!

I have found some events/actions here .html#events

dispatchAction({
    type: 'legendToggleSelect',
    // legend name
    name: string
})

Does anyone know how can I use actions/events to apply it to my custom html legend?

I have created a pie chart using ECharts. Thus, I would like to use a custom HTML for my legend but I don't know how to use their events.

Here is a fiddle of what I've done so far: https://jsfiddle/fwpzjnt7/1/

I don't know the right function/event to make my custom legend clickable so I can show/hide the selected data!

I have found some events/actions here https://www.echartsjs./en/api.html#events

dispatchAction({
    type: 'legendToggleSelect',
    // legend name
    name: string
})

Does anyone know how can I use actions/events to apply it to my custom html legend?

Share Improve this question edited Feb 21, 2020 at 11:43 johannesMatevosyan 2,2382 gold badges36 silver badges43 bronze badges asked Feb 11, 2020 at 17:03 ElchyElchy 1816 silver badges17 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Although this is an old question, I have stumbled upon the same problem recently and I have found an answer.

I will leave it here, in case someone will need it.

I used the API of echarts, namely legendToggleSelect action:

dispatchAction({
    type: 'legendToggleSelect',
    name: string // the name of the series you want to toggle
})

More details here: https://echarts.apache/en/api.html#action.legend.legendToggleSelect

You can also hide the default legend (add to the option list legend: {show: false},)

I am assuming you are looking for something like the below chart where user will be able to filter chart.

var myChart = echarts.init(document.getElementById('main'));
var option = {
  legend: {
    orient: 'vertical',
    left: 10,
    data: ['a', 'b', 'c', 'd', 'e']
  },
  series: [{
    name: '访问来源',
    type: 'pie',
    radius: ['0%', '70%'],
    avoidLabelOverlap: false,
    labelLine: {
      normal: {
        show: false
      }
    },
    data: [{
        value: 335,
        name: 'a'
      },
      {
        value: 310,
        name: 'b'
      },
      {
        value: 234,
        name: 'c'
      },
      {
        value: 135,
        name: 'd'
      },
      {
        value: 1548,
        name: 'e'
      }
    ]
  }]
};


myChart.setOption(option);
<script src="https://cdnjs.cloudflare./ajax/libs/echarts/3.7.2/echarts.min.js"></script>
<div id="main" style="width: 400px;height:400px;"></div>

发布评论

评论列表(0)

  1. 暂无评论