应无所住,而生其心
排名
1
文章
861
粉丝
112
评论
163
net core webapi post传递参数
庸人 : 确实坑哈,我也是下班好了好几次,发现后台传递对象是可以的,但...
百度编辑器自定义模板
庸人 : 我建议换个编辑器,因为现在百度富文本已经停止维护了,用tinymec...
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术

echarts折线图使用示例。包含颜色渐变,节点样式,图例legend样式等

3585人阅读 2020/6/21 18:57 总访问:5232356 评论:0 收藏:0 手机
分类: 前端

设计图如下

代码如下

  1. <!-- 学习趋势图 -->
  2. <template>
  3. <div class="learnTrendChartContainer">
  4. <div style="position:absolute;right: 6px;z-index: 1000;">
  5. <select class="yearSelect">
  6. <option>2022</option>
  7. <option>2023</option>
  8. </select>
  9. </div>
  10. <div>
  11. <div id="labroom-trend-chart" class="labroom-trend-chart" />
  12. </div>
  13. </div>
  14. </template>
  15. <script lang="ts">
  16. export default {
  17. // 组件名字
  18. name: 'LearnTrendChart',
  19. // 组件参数
  20. props: {
  21. },
  22. data() {
  23. return {
  24. nowPeopleCount: 2895,
  25. termPeopleCount: 1025905,//学期累计人次
  26. }
  27. },
  28. mounted() {
  29. this.createChartByDay()
  30. },
  31. methods: {
  32. createChartByDay() {
  33. // 基于准备好的dom,初始化echarts实例
  34. const myChart = this.$echarts.init(document.getElementById('labroom-trend-chart'))
  35. const option = {
  36. // 图表颜色设置
  37. color: ['#F2C52A', '#23FFFC', '#1C8DFF', '#FF0087', '#FFBF00'],
  38. tooltip: {
  39. trigger: 'axis',
  40. backgroundColor: "rgba(18,103,167,0.9)",
  41. borderColor: "#01DCF3",
  42. textStyle: {
  43. color: "#fff",
  44. fontSize: 12
  45. },
  46. icon: "rect",
  47. symbol: "rect",
  48. axisPointer: {
  49. label: {
  50. // y轴格式化函数官方文档:https://echarts.apache.org/zh/option.html#tooltip.axisPointer.label.formatter
  51. formatter: function (params) {
  52. console.log(params)
  53. return params.value + "月";
  54. }
  55. },
  56. },
  57. // 分别设置四个方向的内边距
  58. padding: [
  59. 6, // 上
  60. 10, // 右
  61. 9, // 下
  62. 10, // 左
  63. ],
  64. valueFormatter: (value) => value + "人次",
  65. // 这里使用了格式化函数,也可以不用,不用的话和设计图区别就是线的示例是原点,而不是长方形,没有找到直接设置成长方形的方法,为了和设计图一样就通过formatter自定义格式
  66. formatter: function (params) {
  67. var result = ''
  68. var dotHtml = '<span style="display:inline-block;margin-right:5px;margin-top:-5px;width:20px;height:7px;background-color:#F2C52A"></span>' // 定义第一个数据前的长方形颜色
  69. var dotHtml2 = '<span style="display:inline-block;margin-right:5px;margin-top:-5px;width:20px;height:7px;background-color:#23FFFC"></span>' // 定义第二个数据前的长方形颜色
  70. var dotHtml3 = '<span style="display:inline-block;margin-right:5px;margin-top:-5px;width:20px;height:7px;background-color:#1C8DFF"></span>' // 定义第二个数据前的长方形颜色
  71. result += "<div>" + params[0].axisValue + "月" + "</div>" +
  72. "<div style='margin-top:2px'>" + dotHtml + " 累计评估量: <span style='display:inline-block;margin-left:5px;'>" + params[0].data + "人次" + "</div>" +
  73. "<div style='margin-top:3px'>" + dotHtml2 + " 累计实验量: <span style='display:inline-block;margin-left:5px;'>" + params[1].data + "人次" + "</div>" +
  74. "<div style='margin-top:3px'>" + dotHtml3 + " 累计项目数: <span style='display:inline-block;margin-left:5px;'>" + params[2].data + "人次</span>" + "</div>";
  75. return result
  76. }
  77. },
  78. // 图例设置
  79. legend: {
  80. // x:'right', //可设定图例在左、右、居中
  81. // padding:[0,50,0,0],
  82. // 只设置距离右边
  83. right: 86,
  84. // circle,rect ,roundRect,triangle,diamond,pin,arrow,none,
  85. //icon:"rect",
  86. data: [{
  87. name: "累计评估量",
  88. // 单独设置图例空心圆,通过设置边框颜色+背景颜色白色实现空心圆
  89. itemStyle: {
  90. color: "#fff",
  91. borderColor: '#F2C52A',
  92. borderWidth: 1,
  93. },
  94. // 单独设置字体颜色
  95. textStyle: {
  96. color: "#F2C52A",
  97. },
  98. },
  99. {
  100. name: "累计实验量",
  101. itemStyle: {
  102. color: "#fff",
  103. borderColor: '23FFFC',
  104. borderWidth: 1,
  105. },
  106. // 单独设置字体颜色
  107. textStyle: {
  108. color: "#23FFFC"
  109. }
  110. },
  111. {
  112. name: "累计项目数",
  113. // 图例空心圆,通过设置边框颜色+背景颜色白色实现空心圆
  114. itemStyle: {
  115. color: "#fff",
  116. borderColor: '1C8DFF',
  117. borderWidth: 1,
  118. },
  119. textStyle: {
  120. color: "#1C8DFF"
  121. }
  122. }
  123. ],
  124. //data: ['累计评估量', '累计实验量', '累计项目数'],
  125. // textStyle: {
  126. // color: "#fff"
  127. // }
  128. },
  129. grid: {
  130. //top: '0%',
  131. left: '0%',
  132. right: '16px',
  133. // bottom: '6%',
  134. containLabel: true
  135. },
  136. xAxis: {
  137. type: 'category',
  138. //* ***************不留白,从原点开始**************
  139. boundaryGap: false, // 不留白,从原点开始
  140. data: ['Mon', 'Tue', 'Wed', 'Thu', "1", "3", "5", "7", "8", "9"],
  141. axisLine: {
  142. lineStyle: {
  143. color: "#678DBA",
  144. }
  145. }
  146. },
  147. yAxis: {
  148. type: 'value',
  149. // echart 去掉网格线。去掉横坐标的线
  150. splitLine: { show: false },
  151. axisLine: {
  152. lineStyle: {
  153. color: "#678DBA",
  154. }
  155. }
  156. },
  157. series: [
  158. {
  159. name: "累计评估量",
  160. label: {
  161. // 格式化输出
  162. formatter: function (params) {
  163. // console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
  164. // console.log(params)
  165. return params.value
  166. },
  167. show: false,
  168. position: 'top'
  169. },
  170. itemStyle: {
  171. normal: {
  172. lineStyle: {
  173. width: 1, //折线宽度
  174. }
  175. }
  176. },
  177. data: [131, 236, 191, 149, 159, 190, 150, 109, 123, 109],
  178. type: 'line',
  179. smooth: true,
  180. symbol: "circle",
  181. symbolSize: [8, 8],
  182. // 黄色的图
  183. areaStyle: {
  184. normal: {
  185. // 颜色渐变函数 前四个参数分别表示四个位置依次为左、下、右、上
  186. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  187. offset: 0,
  188. color: 'rgba(242, 197, 42,0.12)'
  189. }, {
  190. offset: 0.34,
  191. color: 'rgba(242, 197, 42,0.10)'
  192. }, {
  193. offset: 1,
  194. color: 'rgba(242, 197, 42,0.02)'
  195. }])
  196. }
  197. }
  198. },
  199. {
  200. name: "累计实验量",
  201. label: {
  202. // 格式化输出
  203. formatter: function (params) {
  204. return params.value
  205. },
  206. show: false,
  207. position: 'top'
  208. },
  209. itemStyle: {
  210. normal: {
  211. lineStyle: {
  212. width: 1, //折线宽度
  213. }
  214. }
  215. },
  216. data: [108, 99, 108, 139, 165, 170, 150, 159, 166, 122],
  217. type: 'line',
  218. symbol: "circle",
  219. symbolSize: [8, 8],
  220. smooth: true,
  221. // 显示出来折线图的面积
  222. areaStyle: {
  223. normal: {
  224. // 颜色渐变函数 前四个参数分别表示四个位置依次为左、下、右、上
  225. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  226. offset: 0,
  227. color: 'rgba(35, 255, 252,0.16)'
  228. }, {
  229. offset: 0.34,
  230. color: 'rgba(35, 255, 252,0.12)'
  231. }, {
  232. offset: 1,
  233. color: 'rgba(35, 255, 252,0.00)'
  234. }])
  235. }
  236. }
  237. },
  238. {
  239. name: "累计项目数",
  240. label: {
  241. // 格式化输出
  242. formatter: function (params) {
  243. // console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
  244. // console.log(params)
  245. return params.value
  246. },
  247. show: false,
  248. position: 'top'
  249. },
  250. itemStyle: {
  251. normal: {
  252. lineStyle: {
  253. width: 1, //折线宽度
  254. },
  255. // color: "#fff",
  256. // borderColor: '#f58f23',
  257. // borderWidth: 1,
  258. }
  259. },
  260. data: [132, 191, 141, 149, 155, 160, 130, 139, 150, 122],
  261. type: 'line',
  262. smooth: true,
  263. symbol: "circle",
  264. symbolSize: [8, 8],
  265. // 显示出来折线图的面积
  266. areaStyle: {
  267. normal: {
  268. // 颜色渐变函数 前四个参数分别表示四个位置依次为左、下、右、上
  269. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  270. offset: 0,
  271. color: 'rgba(28, 141, 255,0.22)'
  272. }, {
  273. offset: 0.34,
  274. color: 'rgba(28, 141, 255,0.16)'
  275. }, {
  276. offset: 1,
  277. color: 'rgba(28, 141, 255,0.00)'
  278. }])
  279. }
  280. }
  281. }
  282. ]
  283. }
  284. myChart.setOption(option)
  285. }
  286. }
  287. }
  288. </script>
  289. <style lang="scss" scoped>
  290. .learnTrendChartContainer {
  291. position: relative;
  292. .labroom-trend-chart {
  293. height: 296px;
  294. width: 100%;
  295. }
  296. .yearSelect {
  297. width: 69px;
  298. font-size: 14px;
  299. text-align: center;
  300. border: 1px solid #01F3FC;
  301. border-radius: 12px;
  302. background-color: rgba(20, 41, 68, 1);
  303. color: #01F3FC;
  304. }
  305. }
  306. </style>

引入组件:

  1. import LearnTrendChart from '@/views/index/component/learnTrendChart.vue'
  2. export default {
  3. components: {
  4. LearnTrendChart
  5. },
  6. }

使用组件:

  1. <LearnTrendChart></LearnTrendChart>

欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)

评价

echarts中tooltip 基本样式问题处理

在echarts中遇到几个样式问题,现总结如下:1、tooltip中样式中 值换行在tooltip中修改加上一句代码formatter:&#39;{b0}:{c...

ionic3实战使用echarts图表(柱状图)

在公司有些东西需要投到大屏幕上去显示,也就是电视显示屏(安卓版的),但是我没普通的html代码并不能打包到上去安装使用...

echarts 显示坐标点echarts 自定义显示坐标点echarts 个性化坐标提升显示

最简单的显示出来,直接在series中对应的数据项里边设置一下label即可label: { show: true, position: &#39;top&...

echarts自定义图表提示框鼠标指上去显示echarts tooltip的使用

官方文档:https://echarts.apache.org/zh/option.html#tooltip 使用的是tooltip,如果只是要显示出来,直接设置trigger: ...

echarts修改横纵坐标颜色修改折线图线的宽度

echarts修改横坐标颜色代码主要是这样的 axisLine:{ lineStyle:{ ...

echarts图例legend颜色各不相同图例legend空心圆

代码如下:legend: { // x:&#39;right&#39;, //可设定图例在左、右、居中 // padding:[0,50,0,0], //...

echarts提示框tooltip属性

tooltip: { show: true, // 是否显示提示框组件 trigger: &#39;axis&#39;, // 触发类型(&#39;item&#39;,...

echarts 仪表盘gauge颜色渐变echarts圆环进度条echarts圆环进度条弧形

效果如下: 配置项代码如下// 基于准备好的dom,初始化echarts实例 const myChart = this.$echarts.init(document.getEl...

echarts 设置x坐标刻度的颜色

是使用axisLabel下面的颜色设置,不是nameTextStyle不要搞混了。nameTextStyle官方解释是坐标轴名称的文字样式,要和坐标轴...

echarts setoption 不重新渲染

Echarts渲染的逻辑如果 echarts 未实例化则进⾏实例化过程,⼀旦实例化,便会在div容器⽣成⼀个 echarts_instance属性,该...

echarts 图表颜色设置饼图颜色渐变

[TOC]echarts 图表颜色设置在外层加一个color数组就行了 color:[&quot;#1890FF&quot;,&quot;#91CB74&quot;,&quot;#FAC858&...

echarts饼图通过grid设置位置不生效饼图设置位置

grid 记得是平面直角坐标系的意思,而仪表盘、饼图这种,是通过设置中心点位置的方式定位的。所以仪表盘、饼图这种应该这样...

Quartz.NET实例动态改变周期调度misfire、Cron

Quartz:Java编写的开源的任务调度作业框架 类似Timer之类定时执行的功能,但是更强大Quartz.NET:是把Quartz转成C# NuGet...

.NET Windows服务发布、安装、卸载、监听脚本服务调试

一、脚本 为方便不用每次都去写安装卸载的脚本1.安装脚本@echooff @echo开始安装【服务】 %SystemRoot%\Microsoft.NET\Fr...

nginx常用命令nginx启动命令nginx重启命令nginx关闭命令nginx测试配置文件是否正确nginx nginx.pid文件丢失报错

启动命令:start nginx 关闭命令:nginx -s stop nginx -s quit nginx -s stop与nginx -s quit区别 Quit is a graceful shu...