当前位置:   article > 正文

Vue ECharts markline设置为legend - 附完整示例_echarts markline 配置图例

echarts markline 配置图例

ECharts:一个基于 JavaScript 的开源可视化图表库

目录

 效果

一、介绍

1、官方文档:Apache ECharts

 二、准备工作

1、安装依赖包

2、示例版本 

三、完整示例


 效果

一、介绍

1、官方文档:Apache ECharts

Apache EChartsApache ECharts,一款基于JavaScript的数据可视化图表库,提供直观,生动,可交互,可个性化定制的数据可视化图表。icon-default.png?t=N7T8https://echarts.apache.org/zh/index.html


 

 二、准备工作

1、安装依赖包

npm install echarts --save

2、示例版本 

"echarts": "^5.4.2",

三、完整示例

  1. <template>
  2. <div id="main"></div>
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. export default {
  7. name: "forExample",
  8. data() {
  9. return {
  10. };
  11. },
  12. mounted() {
  13. this.$nextTick(() => {
  14. this.initChart();
  15. });
  16. },
  17. methods: {
  18. initChart() {
  19. var chartDom = document.getElementById("main");
  20. var myChart = echarts.init(chartDom);
  21. var option;
  22. const data = [50, 64, 96, 80, 70, 82, 73];
  23. const meanValue = data.reduce((pre, cur) => pre + cur, 0) / data.length;
  24. option = {
  25. tooltip: {},
  26. legend: {
  27. data: [
  28. { name: "Sale" },
  29. {
  30. /* TIP: 设置虚线 */
  31. name: "平均值",
  32. lineStyle: {
  33. type: "dotted",
  34. width: 3,
  35. color: "#fd0100",
  36. },
  37. },
  38. ],
  39. selectedMode: false, //图例选择模式关闭
  40. },
  41. xAxis: {
  42. data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  43. },
  44. yAxis: {},
  45. series: [
  46. {
  47. name: "Sale",
  48. type: "bar",
  49. data,
  50. markLine: {
  51. lineStyle: {
  52. color: "#fd0100",
  53. width: 3,
  54. height: 14,
  55. },
  56. data: [
  57. {
  58. yAxis: meanValue,
  59. },
  60. ],
  61. label: {
  62. position: "insideEndTop",
  63. formatter: (params) => "平均值:" + params.value,
  64. padding: [0, 20, 0, 0],
  65. fontSize: 18,
  66. distance: 0,
  67. },
  68. },
  69. },
  70. {
  71. /* TIP: 增加的series */
  72. type: "line",
  73. symbol: "none",
  74. name: "平均值",
  75. color: "transparent",
  76. },
  77. ],
  78. };
  79. option && myChart.setOption(option);
  80. },
  81. },
  82. };
  83. </script>
  84. <style lang="less" scoped>
  85. #main {
  86. width: 1000px;
  87. height: 500px;
  88. }
  89. </style>
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/114741?site
推荐阅读