EchartsDome.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class="echartsDome">
  3. <div class="echartsDome_title">{{ title }}</div>
  4. <div class="echartsDome_chart" ref="chartContainer"></div>
  5. </div>
  6. </template>
  7. <script>
  8. import * as echarts from "echarts";
  9. export default {
  10. name: "EchartsDome",
  11. props: {
  12. title: {
  13. type: String,
  14. default: "图表标题",
  15. },
  16. },
  17. data() {
  18. return {
  19. chart: null,
  20. };
  21. },
  22. mounted() {
  23. this.initChart();
  24. },
  25. methods: {
  26. initChart() {
  27. this.chart = echarts.init(this.$refs.chartContainer);
  28. let option = {
  29. tooltip: {
  30. trigger: "axis", // 坐标轴触发提示
  31. axisPointer: { type: "shadow" },
  32. },
  33. legend: {
  34. data: ["tokyo", "london"],
  35. textStyle: { color: "#fff" }, // 图例文字颜色
  36. },
  37. xAxis: {
  38. type: "category",
  39. data: [
  40. "Jan",
  41. "Feb",
  42. "Mar",
  43. "Apr",
  44. "May",
  45. "Jun",
  46. "Jul",
  47. "Aug",
  48. "Sep",
  49. "Oct",
  50. "Nov",
  51. ],
  52. axisLine: { lineStyle: { color: "#fff" } }, // 坐标轴颜色
  53. axisTick: { show: false }, // 隐藏刻度
  54. splitLine: { show: false }, // 隐藏分割线
  55. },
  56. yAxis: {
  57. type: "value",
  58. max: 30,
  59. axisLine: { lineStyle: { color: "#fff" } },
  60. splitLine: {
  61. lineStyle: {
  62. type: "dashed", // 虚线网格
  63. color: "#fff",
  64. },
  65. },
  66. },
  67. series: [
  68. {
  69. name: "调用次数",
  70. type: "line",
  71. data: [7, 7, 15, 19, 21, 22, 25, 26, 23, 19, 12], // 模拟数据
  72. lineStyle: { color: "#42a5f5" }, // 蓝色线条
  73. itemStyle: { color: "#42a5f5" }, // 节点颜色
  74. symbol: "circle", // 节点形状
  75. symbolSize: 6, // 节点大小
  76. },
  77. {
  78. name: "平均响应时间",
  79. type: "line",
  80. data: [3, 3, 6, 12, 15, 17, 18, 17, 14, 10, 6], // 模拟数据
  81. lineStyle: { color: "#4caf50" }, // 绿色线条
  82. itemStyle: { color: "#4caf50" },
  83. symbol: "circle",
  84. symbolSize: 6,
  85. },
  86. ],
  87. };
  88. // 绘制图表
  89. this.chart.setOption(option);
  90. },
  91. },
  92. };
  93. </script>
  94. <style scoped>
  95. .echartsDome {
  96. width: 100%;
  97. height: 400px;
  98. /* background-color: #222;
  99. color: #fff; */
  100. padding: 20px;
  101. box-sizing: border-box;
  102. }
  103. .echartsDome_title {
  104. font-size: 16px;
  105. /* font-weight: bold; */
  106. }
  107. .echartsDome_chart {
  108. width: 100%;
  109. height: 360px;
  110. }
  111. </style>