@Apache ECharts

需要指定图表容器高度
更多使用,请访问 Apache ECharts
其它图标库:ApxchartsChartjs
安装 Installation
npm i echarts -S
引入 Import
可以全部引入;也可以按需引入-推荐
使用 Usage
示例给出了所有的图表使用实例。只需修改数据集即可
HTML5
Vue
需要调整示例代码为Vue,以饼图为例,按需引入,需要调整的有:
DOM节点的获取 - ref
配置项 - onmounted
调整后的示例代码如下
逻辑
import { ref, onMounted } from 'vue';
import * as echarts from 'echarts/core';
import { TooltipComponent, LegendComponent } from 'echarts/components';
import { PieChart } from 'echarts/charts';
import { LabelLayout } from 'echarts/features';
import { CanvasRenderer } from 'echarts/renderers';
let main = ref(null)
echarts.use([
  TooltipComponent,
  LegendComponent,
  PieChart,
  CanvasRenderer,
  LabelLayout
]);

onMounted(() => {
  let myChart = echarts.init(main.value);
  let option;

  option = {
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '5%',
      left: 'center'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: false,
          position: 'center'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 40,
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: [
          { value: 1048, name: 'Search Engine' },
          { value: 735, name: 'Direct' },
          { value: 580, name: 'Email' },
          { value: 484, name: 'Union Ads' },
          { value: 300, name: 'Video Ads' }
        ]
      }
    ]
  };
  option && myChart.setOption(option);
})
结构 - 略
样式 - 略