Echarts可视化教程

  1. 网站首页
  2. 百度ECharts
  3. ECharts实例
  4. ECharts入门
  5. 地图大全
  6. ECharts官网

如何在Vue的框架下快速搭建统计图表?

//1、安装脚手架
npm install -g @vue/cli
npm install vue-chartjs chart.js

//2、新建Chart.vue组件
<template>
  <div class="chart">
    <canvas ref="chart"></canvas>
  </div>
</template>

<script>
import { Line } from 'vue-chartjs'

export default {
  extends: Line,
  props: ['data', 'options'],
  mounted () {
    this.renderChart(this.data, this.options)
  }
}
</script>

<style scoped>
.chart {
  position: relative;
  width: 100%;
  height: 400px;
}
</style>

//3、页面引入
<template>
  <div class="statistics">
    <chart :data="chartData" :options="chartOptions"></chart>
  </div>
</template>

<script>
import Chart from '@/components/Chart'

export default {
  components: {
    Chart
  },
  data () {
    return {
      chartData: {
        labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
        datasets: [
          {
            label: 'Sales',
            backgroundColor: 'rgba(75, 192, 192, 0.2)',
            borderColor: 'rgba(75, 192, 192, 1)',
            data: [65, 59, 80, 81, 56, 55, 40]
          },
          {
            label: 'Profit',
            backgroundColor: 'rgba(255, 99, 132, 0.2)',
            borderColor: 'rgba(255, 99, 132, 1)',
            data: [28, 48, 40, 19, 86, 27, 90]
          }
        ]
      },
      chartOptions: {
        responsive: true,
        maintainAspectRatio: false
      }
    }
  }
}
</script>

<style scoped>
.statistics {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
</style>
点击展开全文

相关文章

  1. Vue统计图表三维立体3D和旋转效果的优化
  2. PHP如何结合Vue处理大数据集的统计图表
  3. 如何用Vue实现文本数据的统计图表
  4. 如何使用Vue实现统计图的实时更新
  5. Vue统计图表如何利用vue-browsersync插件实现跨浏览器兼容性

热门workflows工作流