• echarts案例之双折线渐变图


    一、此案例基于Vue3+ts,效果展示:

    二、单个属性的值:

    1、tooltip中的trigger属性

    值:

    1.axis是鼠标hover到一条柱状图显示全部数据

    2.item是鼠标hover到折线点显示相应数据

    2、tooltip中的type属性

    不写这个属性,默认为line

    值:

    1.line 鼠标移上去为竖直线

    2.cross 鼠标移上去显示十字线

    3.shadow 鼠标移上去显示灰色方框

    3、legend中的icon属性

    值:

    1.circle 圆形

    2.rect 方形

    3.roundRect 圆角方形

    4.triangle 三角形

    5.diamond 菱形

    6.pin 定位点

    7.arrow 箭头

    4、series中的symbol属性

    1.circle 实心圆

    2.rectangle 实心方块

    3.triangle 实心三角

    4.diamond 实心菱形

    5.emptyCircle 空心圆

    6.emptyRectangle 空心方块

    7.emptyTriangle 空心三角

    8.emptyDiamond 空心菱形

    9.heart 心形

    10.droplet 水滴

    11.pin 定位点

    12.arrow 箭头

    13.star 五角星,'star' + n(n>=3)可变化出N角星,如指定为'star6'则可以显示6角星 

    三、完整代码如下:

    1. <script setup lang="ts" name="airQuality-line">
    2. import { ref, onMounted } from 'vue';
    3. import * as echarts from 'echarts';
    4. const lineRef = ref();
    5. let myChart: any = null; // echarts实例对象
    6. onMounted(() => {
    7. initCharts();
    8. });
    9. // 变化尺寸
    10. const onResize = (resize: any) => {
    11. console.log('resize: ', resize);
    12. myChart && myChart.resize();
    13. };
    14. window.addEventListener('resize', onResize);
    15. const initCharts = () => {
    16. let option = {
    17. // 鼠标hover出现的提示框组件
    18. tooltip: {
    19. trigger: 'axis', // 触发类型:axis是鼠标hover到一条柱状图显示全部数据;item是鼠标hover到折线点显示相应数据
    20. type: 'line', // 默认为line;line鼠标移上去为竖直线;cross鼠标移上去显示十字线;shadow鼠标移上去显示灰色方框
    21. // 坐标轴指示器
    22. axisPointer: {
    23. lineStyle: {
    24. color: 'rgba(69, 173, 175, 1)',
    25. },
    26. },
    27. backgroundColor: 'rgba(69, 173, 175, 0.5)',
    28. borderWidth: 0,
    29. textStyle: {
    30. color: '#fff',
    31. fontSize: 14,
    32. },
    33. },
    34. // 图例
    35. legend: {
    36. icon: 'rect', // circle圆形;rect方形;roundRect圆角方形;triangle三角形;diamond菱形;pin定位点;arrow导航三角指针
    37. data: ['优', '差'],
    38. itemWidth: 20,
    39. itemHeight: 5,
    40. itemGap: 15, // 间隔
    41. right: 10,
    42. textStyle: {
    43. fontSize: 12,
    44. color: '#59697A',
    45. },
    46. },
    47. // 图表位置
    48. grid: {
    49. left: '2%',
    50. right: '4%',
    51. top: '15%',
    52. bottom: '0%',
    53. containLabel: true, // 是否包含坐标刻度
    54. },
    55. xAxis: [
    56. {
    57. type: 'category',
    58. boundaryGap: false, // 散点图的留白策略
    59. axisLine: {
    60. lineStyle: {
    61. color: '#415264',
    62. width: 2,
    63. type: 'solid',
    64. },
    65. },
    66. axisLabel: {
    67. color: '#59697A',
    68. fontSize: 12,
    69. },
    70. axisTick: {
    71. show: false,
    72. },
    73. data: ['0:00', '3:00', '6:00', '9:00', '12:00', '15:00', '18:00', '21:00', '24:00'],
    74. },
    75. ],
    76. yAxis: [
    77. {
    78. type: 'value',
    79. axisTick: {
    80. show: false,
    81. },
    82. axisLine: {
    83. lineStyle: {
    84. color: '#57617B',
    85. },
    86. },
    87. axisLabel: {
    88. // 改变y轴字体颜色和大小
    89. // formatter: '{value}间 ', // 给y轴添加单位
    90. color: '#59697A',
    91. fontSize: 12,
    92. },
    93. splitLine: {
    94. lineStyle: {
    95. color: '#57617B',
    96. type: 'dashed',
    97. },
    98. },
    99. },
    100. ],
    101. series: [
    102. {
    103. name: '优',
    104. type: 'line',
    105. smooth: true, // 是否为平滑曲线
    106. lineStyle: {
    107. width: 1,
    108. },
    109. symbol: 'circle',
    110. symbolSize: 5,
    111. showSymbol: false, // 是否显示数据点
    112. areaStyle: {
    113. // 设置渐变色
    114. color: new echarts.graphic.LinearGradient(
    115. 0,
    116. 0,
    117. 0,
    118. 1,
    119. [
    120. {
    121. offset: 0,
    122. color: 'rgba(127, 254, 223,0.7)',
    123. },
    124. {
    125. offset: 0.8,
    126. color: 'rgba(5, 31, 43,0.5)',
    127. },
    128. ],
    129. false
    130. ),
    131. },
    132. itemStyle: {
    133. color: '#7DFFE8',
    134. borderWidth: 1,
    135. },
    136. data: [18, 20, 32, 15, 26, 36, 22, 15, 21],
    137. },
    138. {
    139. name: '差',
    140. type: 'line',
    141. smooth: true,
    142. symbol: 'circle',
    143. symbolSize: 5,
    144. showSymbol: false,
    145. lineStyle: {
    146. width: 1,
    147. },
    148. areaStyle: {
    149. color: new echarts.graphic.LinearGradient(
    150. 0,
    151. 0,
    152. 0,
    153. 1,
    154. [
    155. {
    156. offset: 0,
    157. color: 'rgba(176, 194, 217,0.7)',
    158. },
    159. {
    160. offset: 0.8,
    161. color: 'rgba(5, 31, 43,0.5)',
    162. },
    163. ],
    164. false
    165. ),
    166. },
    167. itemStyle: {
    168. color: '#EBF9FE',
    169. borderWidth: 1,
    170. },
    171. data: [32, 25, 18, 36, 22, 15, 28, 34, 28],
    172. },
    173. ],
    174. };
    175. myChart = echarts.init(lineRef.value as HTMLDivElement);
    176. myChart.setOption(option, true);
    177. };
    178. script>
    179. <style lang="scss" scoped>
    180. .content-box {
    181. width: 100%;
    182. height: 100%;
    183. }
    184. style>

  • 相关阅读:
    S标签肽,H2N-KETAAAKFERQHMDS-OH
    网络配置(IP、NETMASK、GATEWAY、DNS、DHCP) <持续更新中>
    Elasticsearch基础
    时间序列常用数据处理
    taro超过3行隐藏显示展开功能
    深入浅出继承
    后端技术盲区大清理:事务还没弄明白的小伙伴赶紧来看一看
    2022/11/20[指针] 通过函数,利用指针将数组a中前n个元素按相反顺序存放
    python之字典的用法
    基于Springboot实现学生毕业离校系统项目【项目源码+论文说明】分享
  • 原文地址:https://blog.csdn.net/weixin_48082900/article/details/134015645