• echarts案例之仪表盘如何单独设置指针颜色?


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

    二、单个属性的值:

    1、单独设置指针的颜色

    series:[

    ......

    {

    ......

     itemStyle: {

              color: 'rgba(161, 255, 249, 1)',

            },

    ......

    }

    ......

    ]

    2、设置最外圈数值的样式

    series:[

    ......

    {

    ......

         detail: {

              offsetCenter: ['50%', '30%'],

              color: 'rgba(61, 255, 243, 1)',

            },

    ......

    }

    ......

    ]

    三、完整代码如下: 

    1. <script setup lang="ts" name="todaySAirQualityIndex-dashboard">
    2. import { ref, onMounted } from 'vue';
    3. import * as echarts from 'echarts';
    4. const barRef = 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. const color = new echarts.graphic.LinearGradient(0, 0, 1, 0, [
    17. {
    18. offset: 0,
    19. color: 'rgba(73, 255, 255, 1)', // 0% 处的颜色
    20. },
    21. {
    22. offset: 0.2,
    23. color: 'rgba(127, 254, 121, 1)', // 100% 处的颜色
    24. },
    25. {
    26. offset: 0.4,
    27. color: 'rgba(255, 217, 84, 1)', // 100% 处的颜色
    28. },
    29. {
    30. offset: 0.6,
    31. color: 'rgba(255, 142, 67, 1)', // 100% 处的颜色
    32. },
    33. {
    34. offset: 0.8,
    35. color: 'rgba(255, 71, 54, 1)', // 100% 处的颜色
    36. },
    37. {
    38. offset: 1,
    39. color: 'rgba(244, 43, 91, 1)', // 100% 处的颜色
    40. },
    41. ]);
    42. const colorSet = [[1, color]];
    43. const rich = {
    44. white: {
    45. fontSize: 50,
    46. color: '#fff',
    47. fontWeight: '500',
    48. padding: [-150, 0, 0, 0],
    49. },
    50. bule: {
    51. fontSize: 70,
    52. fontFamily: 'DINBold',
    53. color: '#fff',
    54. fontWeight: '700',
    55. padding: [-120, 0, 0, 0],
    56. },
    57. radius: {
    58. width: 350,
    59. height: 80,
    60. // lineHeight:80,
    61. borderWidth: 1,
    62. borderColor: '#0092F2',
    63. fontSize: 50,
    64. color: '#fff',
    65. backgroundColor: '#1B215B',
    66. borderRadius: 20,
    67. textAlign: 'center',
    68. },
    69. size: {
    70. height: 400,
    71. padding: [100, 0, 0, 0],
    72. },
    73. };
    74. let option = {
    75. tooltip: {
    76. show: false,
    77. },
    78. series: [
    79. {
    80. type: 'gauge',
    81. center: ['50%', '75%'],
    82. radius: '95%',
    83. startAngle: '180',
    84. endAngle: '0',
    85. pointer: {
    86. show: true,
    87. width: 5,
    88. length: '68%',
    89. color: '#fff',
    90. },
    91. detail: {
    92. formatter: function (value: any) {
    93. return value;
    94. },
    95. rich: rich,
    96. // fontWeight: 'bolder',
    97. // 数值位置
    98. offsetCenter: ['50%', '30%'],
    99. color: 'rgba(61, 255, 243, 1)',
    100. },
    101. data: [
    102. {
    103. name: '空气质量',
    104. value: (40 / 100) * 100,
    105. },
    106. ],
    107. title: {
    108. show: true,
    109. fontSize: 14,
    110. color: '#ACCAC9',
    111. // 位置
    112. offsetCenter: ['-20%', '30%'],
    113. },
    114. // 指针的颜色
    115. itemStyle: {
    116. color: 'rgba(161, 255, 249, 1)',
    117. },
    118. axisLine: {
    119. show: true,
    120. lineStyle: {
    121. color: colorSet,
    122. width: 12,
    123. },
    124. },
    125. axisTick: {
    126. show: false,
    127. },
    128. splitLine: {
    129. show: false,
    130. length: 10,
    131. lineStyle: {
    132. color: '#00377a',
    133. width: 2,
    134. type: 'solid',
    135. },
    136. },
    137. axisLabel: {
    138. show: false,
    139. formatter: function (v: any) {
    140. return v.toFixed(0);
    141. },
    142. },
    143. animationDuration: 4000,
    144. },
    145. {
    146. name: '灰色内圈', //刻度背景
    147. type: 'gauge',
    148. z: 2,
    149. center: ['50%', '75%'],
    150. radius: '70%',
    151. startAngle: '180',
    152. endAngle: '0',
    153. //center: ["50%", "75%"], //整体的位置设置
    154. axisLine: {
    155. // 坐标轴线
    156. lineStyle: {
    157. // 属性lineStyle控制线条样式(刻度线样式)
    158. color: [[1, 'rgba(82, 255, 252, 0.3)']],
    159. fontSize: 20,
    160. width: 2,
    161. opacity: 1, //刻度背景宽度
    162. },
    163. },
    164. splitLine: {
    165. show: false,
    166. },
    167. axisLabel: {
    168. // show: false,
    169. distance: -70,
    170. color: 'rgba(82, 255, 252, 0.8)',
    171. fontSize: 12,
    172. formatter: function (v: any) {
    173. return v.toFixed(0);
    174. },
    175. },
    176. pointer: {
    177. show: false,
    178. },
    179. axisTick: {
    180. show: false,
    181. },
    182. detail: {
    183. show: 0,
    184. },
    185. },
    186. {
    187. name: '白色圈刻度',
    188. type: 'gauge',
    189. center: ['50%', '75%'],
    190. radius: '95%',
    191. startAngle: 180, //刻度起始
    192. endAngle: 0, //刻度结束
    193. min: 0,
    194. max: 100,
    195. splitNumber: 10,
    196. z: 4,
    197. axisTick: {
    198. show: false,
    199. },
    200. splitLine: {
    201. length: 8, //刻度节点线长度
    202. lineStyle: {
    203. width: 2,
    204. color: 'rgba(82, 255, 252, 0.8)',
    205. }, //刻度节点线
    206. },
    207. axisLabel: {
    208. show: false,
    209. color: 'rgba(82, 255, 252, 0.8)',
    210. fontSize: 14,
    211. formatter: function (v: any) {
    212. return v.toFixed(0);
    213. },
    214. }, //刻度节点文字颜色
    215. pointer: {
    216. show: false,
    217. },
    218. axisLine: {
    219. lineStyle: {
    220. opacity: 0,
    221. },
    222. },
    223. detail: {
    224. show: false,
    225. },
    226. data: [
    227. {
    228. value: 0,
    229. name: '',
    230. },
    231. ],
    232. },
    233. {
    234. //内圆
    235. type: 'pie',
    236. radius: '35%',
    237. center: ['50%', '75%'],
    238. z: 1,
    239. itemStyle: {
    240. color: new echarts.graphic.RadialGradient(
    241. 0.5,
    242. 1,
    243. 1,
    244. [
    245. { offset: 0.5, color: '#1f545c' },
    246. { offset: 1, color: '#41a1a7' },
    247. ],
    248. false
    249. ),
    250. label: {
    251. show: false,
    252. },
    253. labelLine: {
    254. show: false,
    255. },
    256. },
    257. emphasis: {
    258. scale: false,
    259. },
    260. label: {
    261. show: false,
    262. },
    263. tooltip: {
    264. show: false,
    265. },
    266. data: [
    267. {
    268. value: 100,
    269. },
    270. {
    271. value: 100,
    272. itemStyle: {
    273. color: 'transparent',
    274. },
    275. },
    276. ],
    277. animationType: 'scale',
    278. startAngle: 180,
    279. },
    280. ],
    281. };
    282. myChart = echarts.init(barRef.value as HTMLDivElement);
    283. myChart.setOption(option, true);
    284. };
    285. script>
    286. <style lang="scss" scoped>
    287. .container {
    288. width: 100%;
    289. height: 100%;
    290. }
    291. style>
  • 相关阅读:
    00后也太惨了,写个作业居然被监视上了
    Java多线程编程核心技术手册 绝了
    LGBM 模型保存为PMML 文件
    ABAP 常用函数分类(持续更新。。。)
    CentOS即将停服,国产化系统替代参考
    简单迅速解决windows电脑下载windows应用商店(Microsoft Store)
    理论第十一课——字符串
    ROS 位置姿态Odometry仿真模拟(gmapping)
    2022杭电多校8(总结+补题)
    Git 教程
  • 原文地址:https://blog.csdn.net/weixin_48082900/article/details/134029533