1. 程式人生 > 其它 >elementui 新增echarts元件

elementui 新增echarts元件

1,install echarts

2,全域性註冊main.js

import echarts from 'echarts'
Vue.prototype.$echarts = echarts

3,頁面使用

<div id="chart1" :style="{ width: '460px', height: '300px' }"></div>

4,js

  mounted() {
    this.drawLine("chart1");
  },

    drawLine(name) {
      // 基於準備好的dom,初始化echarts例項
      let myChart = this
.$echarts.init(document.getElementById(name)); // 繪製圖表 let option1 = { title: { text: "考試場次統計" }, xAxis: { //x軸 data: [ "一月", "二月", "三月", "四月", "五月", "六月", "七月",
"八月", "九月", "十月", "十一月", "十二月", ], axisTick: { //刻度 show: false, }, axisLabel: { color: "#333", }, axisLine: { //軸線 lineStyle: { color:
"#ccc", }, }, }, yAxis: { name: "", nameTextStyle: { color: "#333", }, axisLabel: { color: "#333", }, axisTick: { show: false, }, splitLine: { show: false, }, axisLine: { //軸線 lineStyle: { color: "#ccc", }, }, }, series: [ { data: [1, 2, 1, 2, 3, 1, 2, 3, 1, 1, 1, 2], type: "line", smooth: true, }, ], }; myChart.setOption(option1); },