Vue 集成echarts 图表组件

桃扇骨 2023-10-18 16:33 242阅读 0赞

第一步:本项目本地安装echarts

cnpm install echarts -D

第二步:全局配置:项目/main.js 文件

// 引入echarts

import echarts from ‘echarts’

Vue.prototype.$echarts = echarts

第三步:相关页面引用echarts,进行页面初始化

  1. <!-- 登录记录图表 -->
  2. <template>
  3. <transition enter-active-class="animated bounceInUp">
  4. <section class="record-chart">
  5. <el-title-header :title="$route.meta.title"></el-title-header>
  6. <div class="chart" style="height: 500px;"></div>
  7. </section>
  8. </transition>
  9. </template>
  10. <script>
  11. export default {
  12. name: 'recordChart',
  13. methods: {
  14. // 初始化echart
  15. initChart () {
  16. var myChart = this.$echarts.init(document.querySelector('.chart'));
  17. myChart.setOption({
  18. color: ['#3398DB'],
  19. tooltip : {
  20. trigger: 'axis',
  21. axisPointer : { // 坐标轴指示器,坐标轴触发有效
  22. type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  23. }
  24. },
  25. grid: {
  26. left: '3%',
  27. right: '4%',
  28. bottom: '3%',
  29. containLabel: true
  30. },
  31. xAxis : [
  32. {
  33. type : 'category',
  34. data : ['08-07', '08-08', '08-09', '08-10', '08-11', '08-12', '08-13'],
  35. axisTick: {
  36. alignWithLabel: true
  37. }
  38. }
  39. ],
  40. yAxis : [
  41. {
  42. type : 'value'
  43. }
  44. ],
  45. series : [
  46. {
  47. name:'总共',
  48. type:'bar',
  49. barWidth: '60%',
  50. data:[10, 52, 200, 334, 390, 330, 220]
  51. }
  52. ]
  53. });
  54. }
  55. },
  56. mounted () {
  57. this.$nextTick(() => {
  58. this.initChart();
  59. })
  60. }
  61. }
  62. </script>

效果展示:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3pob3V6aGl3ZW5nYW5n_size_16_color_FFFFFF_t_70

发表评论

表情:
评论列表 (有 0 条评论,242人围观)

还没有评论,来说两句吧...

相关阅读

    相关 VUE + ECharts实现图表

    因为这里演示了多种图表,使用的 echarts 引入方式是引入的所有组件,因此体积会比较大,如果在项目中对体积要求比较苛刻,也可以只按需引入需要的模块。 1.安装echar

    相关 Vue 轻量级图表组件

    Vue 轻量级图表组件 当遇到需要在网页上绘制图表的场景时,一般会使用两个库:D3.js 和 Chart.js 。但其实你根本不需要这么重量级的库。有时候你只希望使用简单...