echarts在vue中的使用

梦里梦外; 2023-06-23 08:57 83阅读 0赞

1.使用npm安装依赖包

npm install echarts -S
或者使用淘宝的镜像
npm install -g cnpm —registry=https://registry.npm.taobao.org
cnpm install echarts -S

2.在main.js中全局引入

  1. // 引入echarts
  2. import echarts from 'echarts'
  3. Vue.prototype.$echarts = echarts

3.在vue中使用

  1. <template>
  2. <div>
  3. <div id="myChart" :style="{width: '300px', height: '300px'}"></div>
  4. </div>
  5. </template>
  6. <script lang="ts">
  7. import {
  8. Component,
  9. Vue,
  10. Watch
  11. } from 'vue-property-decorator';
  12. import {
  13. Action,
  14. State
  15. } from 'vuex-class'
  16. import fa from "element-ui/src/locale/lang/fa";
  17. import {getCrowds,addBatch,getGivingCoupons} from '@/common/fetch'
  18. @Component({
  19. mixins:[],
  20. components: {
  21. }
  22. })
  23. export default class AddProduct extends Vue {
  24. show(){
  25. // 基于准备好的dom,初始化echarts实例
  26. let myChart = this.$echarts.init(document.getElementById('myChart'))
  27. // 绘制图表
  28. myChart.setOption({
  29. color:['#9AC0F3'],
  30. xAxis: {
  31. type: 'category',
  32. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  33. },
  34. yAxis: {
  35. type: 'value'
  36. },
  37. series: [{
  38. data: [820, 932, 901, 934, 1290, 1330, 1320],
  39. type: 'line',
  40. itemStyle : { normal: {label : {show: true}}},
  41. smooth: true
  42. }]
  43. });
  44. }
  45. mounted(){
  46. this.show()
  47. }
  48. }
  49. </script>
  50. <style scoped>
  51. </style>

发表评论

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

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

相关阅读

    相关 Vue使用Echarts

    前端可视化是一个前端最基本的技能,要想做的好看,还是得借助一下百度家的echarts,那要怎么在Vue中使用echarts?这个官网没有给出实例,实例基本都是在jquery里面