Some commonly used APIs in Echarts

ECharts is an open source visualization library based on JavaScript that provides a rich API that can be used to create various interactive charts. The following are some commonly used ECharts APIs:

1. **echarts.init()**: Initialize the ECharts instance and accept a DOM container as a parameter.

var myChart = echarts.init(document.getElementById('chart-container'));

2. **myChart.setOption()**: Set the configuration items and data of the chart. You can pass in an object containing the chart configuration.

myChart.setOption({
  title: {
    text: '柱状图示例'
  },
  xAxis: {
    data: ['A', 'B', 'C', 'D', 'E'],
  },
  yAxis: {},
  series: [{
    name: '销量',
    type: 'bar',
    data: [5, 20, 36, 10, 15]
  }]
});

3. **myChart.resize()**: Adjust the size of the chart to adapt to changes in the container.

window.addEventListener('resize', function() {
  myChart.resize();
});

4. **myChart.on()**: Bind an event listener to monitor various interactive events of the chart.

myChart.on('click', function(params) {
  console.log(params);
});

5. **echarts.registerMap()**: Register map data, used to draw map type charts.

echarts.registerMap('china', chinaMapData);

6. **echarts.dispose()**: Destroy the chart instance and release resources.

myChart.dispose();

These are just some of the APIs of ECharts. ECharts also provides many other methods and configuration items for drawing different types of charts, controlling chart styles and interactions, etc. You can check the ECharts official documentation for more detailed API descriptions and examples: [ECharts official documentation](https://echarts.apache.org/zh/api.html).

Guess you like

Origin blog.csdn.net/qq_68299987/article/details/135140084