ecomFE基于 echarts5 & vue3封装的 echarts
https://github.com/ecomfe/vue-echarts/blob/main/README.zh-Hans.md

@vue3 安装

  1. npm install echarts vue-echarts
  • resize-detector

vue3

  1. import { createApp } from 'vue'
  2. import ECharts from 'vue-echarts'
  3. import { use } from "echarts/core";
  4. // 手动引入 ECharts 各模块来减小打包体积
  5. import {
  6. CanvasRenderer
  7. } from 'echarts/renderers'
  8. import {
  9. BarChart
  10. } from 'echarts/charts'
  11. import {
  12. GridComponent,
  13. TooltipComponent
  14. } from 'echarts/components'
  15. use([
  16. CanvasRenderer,
  17. BarChart,
  18. GridComponent,
  19. TooltipComponent
  20. ]);
  21. const app = createApp(...)
  22. // 全局注册组件(也可以使用局部注册)
  23. app.component('v-chart', ECharts)
  24. app.mount(...)

component

  1. <template>
  2. <v-chart class="chart" :option="option" />
  3. </template>
  4. <script>
  5. import { use } from "echarts/core";
  6. import { CanvasRenderer } from "echarts/renderers";
  7. import { PieChart } from "echarts/charts";
  8. import {
  9. TitleComponent,
  10. TooltipComponent,
  11. LegendComponent
  12. } from "echarts/components";
  13. import VChart, { THEME_KEY } from "vue-echarts";
  14. import { ref, defineComponent } from "vue";
  15. use([
  16. CanvasRenderer,
  17. PieChart,
  18. TitleComponent,
  19. TooltipComponent,
  20. LegendComponent
  21. ]);
  22. export default defineComponent({
  23. name: "HelloWorld",
  24. components: {
  25. VChart
  26. },
  27. provide: {
  28. [THEME_KEY]: "dark"
  29. },
  30. setup: () => {
  31. const option = ref({
  32. title: {
  33. text: "Traffic Sources",
  34. left: "center"
  35. },
  36. tooltip: {
  37. trigger: "item",
  38. formatter: "{a} <br/>{b} : {c} ({d}%)"
  39. },
  40. legend: {
  41. orient: "vertical",
  42. left: "left",
  43. data: ["Direct", "Email", "Ad Networks", "Video Ads", "Search Engines"]
  44. },
  45. series: [
  46. {
  47. name: "Traffic Sources",
  48. type: "pie",
  49. radius: "55%",
  50. center: ["50%", "60%"],
  51. data: [
  52. { value: 335, name: "Direct" },
  53. { value: 310, name: "Email" },
  54. { value: 234, name: "Ad Networks" },
  55. { value: 135, name: "Video Ads" },
  56. { value: 1548, name: "Search Engines" }
  57. ],
  58. emphasis: {
  59. itemStyle: {
  60. shadowBlur: 10,
  61. shadowOffsetX: 0,
  62. shadowColor: "rgba(0, 0, 0, 0.5)"
  63. }
  64. }
  65. }
  66. ]
  67. });
  68. return { option };
  69. }
  70. });
  71. </script>
  72. <style scoped>
  73. .chart {
  74. height: 400px;
  75. }
  76. </style>