说明

要求做表格类型竖着折线图

示例图

QQ截图20190625091924.png

HTML代码

  1. <button id="btn1">某单位1按钮</button>
  2. <button id="btn2">某单位2按钮</button>
  3. <div id="main" style="width: 50%;height:400px;"></div>

JS代码

  1. <script src="js/jquery-1.6.2.min.js"></script>
  2. <script src="js/echarts.min.js"></script>
  3. <script>
  4. $(function () {
  5. var jsonData={
  6. backgroundColor: '#001534',
  7. topData:{
  8. planTitle:"计划值1",
  9. planLineOne:"2017数据1",
  10. planLineTwo:"2018数据2",
  11. topPlanTipIsTrue:true
  12. },
  13. topColor:["rgba(0,255,91,0.5)","rgba(0,255,91,1)","#18daff","#fffa4a"],
  14. yAxisText1:[
  15. {value :-15,text:""},
  16. {value :-15,text:"↓ 18",upIsTrue:false},
  17. {value :-15,text:"↑ 4664",upIsTrue:true},
  18. {value :-15,text:""},
  19. {value :-15,text:"↓ 183",upIsTrue:false},
  20. {value :-15,text:"↓ 184",upIsTrue:false},
  21. {value :-15,text:""},
  22. {value :-15,text:"↓ 185",upIsTrue:false},
  23. {value :-15,text:"↑ 1855",upIsTrue:true},
  24. {value :-15,text:"↑ 18555",upIsTrue:true},
  25. {value :-15,text:""},
  26. {value :-15,text:"↑ 18555",upIsTrue:true},
  27. {value :-15,text:"↑ 1855",upIsTrue:true}
  28. ],
  29. yAxisText2:[
  30. {value :-30,text:""},
  31. {value :-30,text:"181"},
  32. {value :-30,text:"1822"},
  33. {value :-30,text:""},
  34. {value :-30,text:"1833"},
  35. {value :-30,text:"1844"},
  36. {value :-30,text:""},
  37. {value :-30,text:"1855"},
  38. {value :-30,text:"1866"},
  39. {value :-30,text:"1877"},
  40. {value :-30,text:""},
  41. {value :-30,text:"1811"},
  42. {value :-30,text:"181111"}
  43. ],
  44. yAxis:{
  45. name:"指标名称(单位)",
  46. data:[
  47. {value:'单位分类0',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(190,290,290,0.3)",padding:3}},
  48. {value:'单位00单位00',textStyle:{align:"left"}},
  49. {value:'单位10单位10单位10',textStyle:{align:"left"}},
  50. {value:'单位分类1',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}},
  51. {value:'单位20',textStyle:{align:"left"}},
  52. {value:'单位30',textStyle:{align:"left"}},
  53. {value:'单位分类2',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}},
  54. {value:'单位40',textStyle:{align:"left"}},
  55. {value:'单位50',textStyle:{align:"left"}},
  56. {value:'单位60',textStyle:{align:"left"}},
  57. {value:'单位分类3',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}},
  58. {value:'单位70',textStyle:{align:"left"}},
  59. {value:'单位80',textStyle:{align:"left"}},
  60. ],
  61. yAxisUnit:[
  62. {yAxis: "单位分类0"},
  63. {yAxis: "单位分类1"},
  64. {yAxis: "单位分类2"},
  65. {yAxis: "单位分类3"}
  66. ]
  67. },
  68. xAxis:{
  69. min:-30,
  70. max:50,
  71. markArea:{
  72. nwIsTrue:true,
  73. borderColor:"rgba(0,255,91,1)",
  74. data: [
  75. {startNum:"-15",endNum:"-30",startColor:"rgba(0,0,0,0.0)",endColor:"rgba(0,0,0,0.0)",text:"实际值\n▼"},
  76. {startNum:"0",endNum:"-15",startColor:"rgba(0,0,0,0.0)",endColor:"rgba(0,0,0,0.0)",text:"增长\n▼"},
  77. {startNum:"0",endNum:"5",startColor:"rgba(255,36,47,0.0)",endColor:"rgba(255,36,47,0.5)",text:"平均值\n▼"},
  78. {startNum:"5",endNum:"25",startColor:"rgba(255,250,74,0.0)",endColor:"rgba(255,250,74,0.5)",text:"前25%\n▼"},
  79. {startNum:"25",endNum:"40",startColor:"rgba(24,218,250,0.0)",endColor:"rgba(24,218,250,0.5)",text:"世界一流标准前\n12.5%\n▼"},
  80. {startNum:"40",endNum:"50",startColor:"rgba(0,255,91,0.0)",endColor:"rgba(0,255,91,0.5)",text:"第一名\n▼"},
  81. ]
  82. },
  83. markAreaData:[
  84. {xAxis:-30},
  85. {xAxis:-15},
  86. {xAxis:5},
  87. {xAxis:25},
  88. {xAxis:40},
  89. {xAxis:50}
  90. // {xAxis:50,label: {borderColor: 'rgba(0,255,91,1)',borderWidth: 3}}
  91. ]
  92. },
  93. seriesData:[
  94. {
  95. data:[
  96. {value :null,ranking:"排名1",Percentage:"1%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}},
  97. {value :14,ranking:"排名2",Percentage:"2%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}},
  98. {value :12,ranking:"排名3",Percentage:"3%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}},
  99. {value :8.25,ranking:"排名4",Percentage:"4%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}},
  100. {value :4.5,ranking:"排名5",Percentage:"5%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  101. {value :12,ranking:"排名6",Percentage:"6%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  102. {value :13.5,ranking:"排名7",Percentage:"7%",Static:"1",symbolSize:0,label: {normal:{}},itemStyle:{}},
  103. {value :15,ranking:"排名8",Percentage:"8%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}},
  104. {value :null,ranking:"排名9",Percentage:"9%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  105. {value :13,ranking:"排名10",Percentage:"10%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  106. {value :14,ranking:"排名11",Percentage:"11%",Static:"1",symbolSize:0,label: {normal:{}},itemStyle:{}},
  107. {value :15,ranking:"排名12",Percentage:"12%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  108. {value :19,ranking:"排名13",Percentage:"13%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}}
  109. ],
  110. lineColor:"#18daff"
  111. },
  112. {data:[
  113. {value :null,ranking:"排名1",Percentage:"1%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}},
  114. {value :24,ranking:"排名2",Percentage:"2%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}},
  115. {value :22,ranking:"排名3",Percentage:"3%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}},
  116. {value :31.5,ranking:"排名4",Percentage:"4%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}},
  117. {value :4.1,ranking:"排名5",Percentage:"5%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  118. {value :22,ranking:"排名6",Percentage:"6%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  119. {value :23.5,ranking:"排名7",Percentage:"7%",Static:"1",symbolSize:0,label: {normal:{}},itemStyle:{}},
  120. {value :25,ranking:"排名8",Percentage:"8%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}},
  121. {value :28,ranking:"排名9",Percentage:"9%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  122. {value :23,ranking:"排名10",Percentage:"10%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  123. {value :24,ranking:"排名11",Percentage:"11%",Static:"1",symbolSize:0,label: {normal:{}},itemStyle:{}},
  124. {value :25,ranking:"排名12",Percentage:"12%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  125. {value :29,ranking:"排名13",Percentage:"13%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}}
  126. ],
  127. lineColor:"#fffa4a"
  128. },
  129. ]
  130. }
  131. var jsonOtherData={
  132. backgroundColor: '#001534',
  133. topData:{
  134. planTitle:"计划值1",
  135. planLineOne:"2017数据1",
  136. planLineTwo:"2018数据2",
  137. topPlanTipIsTrue:false
  138. },
  139. topColor:["rgba(0,255,91,0.5)","rgba(0,255,91,1)","#fff","blue"],
  140. yAxisText1:[
  141. {value :-15,text:""},
  142. {value :-15,text:"↓ 18",upIsTrue:false},
  143. {value :-15,text:"↓ 182",upIsTrue:false},
  144. {value :-15,text:""},
  145. {value :-15,text:"↑ 183",upIsTrue:true},
  146. {value :-15,text:"↑ 184",upIsTrue:true},
  147. {value :-15,text:""},
  148. {value :-15,text:"↓ 185",upIsTrue:false},
  149. {value :-15,text:"↑ 1855",upIsTrue:true},
  150. {value :-15,text:"↑ 18555",upIsTrue:true},
  151. {value :-15,text:""},
  152. {value :-15,text:"↑ 18555",upIsTrue:true},
  153. {value :-15,text:"↓ 1855",upIsTrue:false}
  154. ],
  155. yAxisText2:[
  156. {value :-30,text:""},
  157. {value :-30,text:"181"},
  158. {value :-30,text:"1822"},
  159. {value :-30,text:""},
  160. {value :-30,text:"1833"},
  161. {value :-30,text:"1844"},
  162. {value :-30,text:""},
  163. {value :-30,text:"1855"},
  164. {value :-30,text:"1866"},
  165. {value :-30,text:"1877"},
  166. {value :-30,text:""},
  167. {value :-30,text:"1811"},
  168. {value :-30,text:"181111"}
  169. ],
  170. yAxis:{
  171. name:"指标名称(单位)",
  172. data:[
  173. {value:'单位分类0',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}},
  174. {value:'单位00单位00',textStyle:{align:"left"}},
  175. {value:'单位10单位10单位10',textStyle:{align:"left"}},
  176. {value:'单位分类1',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}},
  177. {value:'单位20单位20单位20单位20',textStyle:{align:"left"}},
  178. {value:'单位30',textStyle:{align:"left"}},
  179. {value:'单位分类2',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}},
  180. {value:'单位40',textStyle:{align:"left"}},
  181. {value:'单位50',textStyle:{align:"left"}},
  182. {value:'单位60',textStyle:{align:"left"}},
  183. {value:'单位分类3',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}},
  184. {value:'单位70',textStyle:{align:"left"}},
  185. {value:'单位80',textStyle:{align:"left"}},
  186. ],
  187. yAxisUnit:[
  188. {yAxis: "单位分类0"},
  189. {yAxis: "单位分类1"},
  190. {yAxis: "单位分类2"},
  191. {yAxis: "单位分类3"}
  192. ]
  193. },
  194. xAxis:{
  195. min:-30,
  196. max:50,
  197. markArea:{
  198. nwIsTrue:false,
  199. borderColor:"rgba(0,255,91,1)",
  200. data: [
  201. {startNum:"-15",endNum:"-30",startColor:"rgba(0,0,0,0.0)",endColor:"rgba(0,0,0,0.0)",text:"实际值\n▼"},
  202. {startNum:"0",endNum:"-15",startColor:"rgba(0,0,0,0.0)",endColor:"rgba(0,0,0,0.0)",text:"增长\n▼"},
  203. {startNum:"0",endNum:"5",startColor:"rgba(255,36,47,0.0)",endColor:"rgba(255,36,47,0.5)",text:"平均值\n▼"},
  204. {startNum:"5",endNum:"25",startColor:"rgba(255,250,74,0.0)",endColor:"rgba(255,250,74,0.5)",text:"前25%\n▼"},
  205. {startNum:"25",endNum:"40",startColor:"rgba(24,218,250,0.0)",endColor:"rgba(24,218,250,0.5)",text:"世界一流标准前\n12.5%\n▼"},
  206. {startNum:"40",endNum:"50",startColor:"rgba(0,255,91,0.0)",endColor:"rgba(0,255,91,0.5)",text:"第一名\n▼"},
  207. ]
  208. },
  209. markAreaData:[
  210. {xAxis:-30},
  211. {xAxis:-15},
  212. {xAxis:5},
  213. {xAxis:25},
  214. {xAxis:40},
  215. {xAxis:50}
  216. ]
  217. },
  218. seriesData:[
  219. {
  220. data:[
  221. {value :null,ranking:"",Percentage:"",Static:"",symbolSize:0,label: {normal:{}},itemStyle:{}},
  222. {value :34,ranking:"排名2",Percentage:"2%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}},
  223. {value :32,ranking:"排名3",Percentage:"3%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}},
  224. {value :32.5,ranking:"排名4",Percentage:"4%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}},
  225. {value :33,ranking:"排名5",Percentage:"5%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  226. {value :32,ranking:"排名6",Percentage:"6%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  227. {value :28.5,ranking:"",Percentage:"",Static:"",symbolSize:0,label: {normal:{}},itemStyle:{}},
  228. {value :25,ranking:"排名8",Percentage:"8%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  229. {value :null,ranking:"排名9",Percentage:"9%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}},
  230. {value :23,ranking:"排名10",Percentage:"10%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
  231. {value :null,ranking:"排名11",Percentage:"11%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}},
  232. {value :null,ranking:"排名12",Percentage:"12%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}},
  233. {value :32,ranking:"排名13",Percentage:"13%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}}
  234. ],
  235. lineColor:"#fff"
  236. },
  237. {data:[
  238. {value:null,ranking:"排名1",Percentage:"1%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}},
  239. {value:25,ranking:"排名2",Percentage:"2%",Static:"0",symbolSize:8,label:{normal:{}},itemStyle:{}},
  240. {value:20,ranking:"排名3",Percentage:"3%",Static:"1",symbolSize:8,label:{normal:{}},itemStyle:{}},
  241. {value:32.5,ranking:"排名4",Percentage:"4%",Static:"0",symbolSize:0,label:{normal:{}},itemStyle:{}},
  242. {value:45,ranking:"排名5",Percentage:"5%",Static:"0",symbolSize:8,label:{normal:{}},itemStyle:{}},
  243. {value:26,ranking:"排名6",Percentage:"6%",Static:"1",symbolSize:8,label:{normal:{}},itemStyle:{}},
  244. {value:26.5,ranking:"排名7",Percentage:"7%",Static:"0",symbolSize:0,label:{normal:{}},itemStyle:{}},
  245. {value:27,ranking:"排名8",Percentage:"8%",Static:"1",symbolSize:8,label:{normal:{}},itemStyle:{}},
  246. {value:4,ranking:"排名9",Percentage:"9%",Static:"1",symbolSize:8,label:{normal:{}},itemStyle:{}},
  247. {value:29,ranking:"排名10",Percentage:"10%",Static:"0",symbolSize:8,label:{normal:{}},itemStyle:{}},
  248. {value:27,ranking:"排名11",Percentage:"11%",Static:"0",symbolSize:0,label:{normal:{}},itemStyle:{}},
  249. {value:25,ranking:"排名12",Percentage:"12%",Static:"1",symbolSize:8,label:{normal:{}},itemStyle:{}},
  250. {value:39,ranking:"排名13",Percentage:"13%",Static:"0",symbolSize:8,label:{normal:{}},itemStyle:{}},
  251. ],
  252. lineColor:"blue"
  253. },
  254. ]
  255. }
  256. drawLine("main",jsonData)
  257. $("#btn1").click(function(){
  258. drawLine("main",jsonData)
  259. })
  260. $("#btn2").click(function(){
  261. drawLine("main",jsonOtherData)
  262. })
  263. });
  264. /*
  265. * drawLine(id,data)
  266. * 配置折线属性,默认series至少2组数据,否则无法绘制背景分割背景色和Y轴分割背景色
  267. * id:目标id string
  268. * data:json
  269. */
  270. function drawLine(id,data){
  271. var _data=data;
  272. //绘制头部
  273. var _tipdata=_data.topData;
  274. var _html= "<div style='position: absolute;left: 4% ; top: 30px; color:#fff;'>";
  275. _html+= " <div style='font-size:12px;'>"+_data.yAxis.name+"</div></div>";
  276. _html+= "<div id='topTitle' style='position: absolute;left: 50% ; top: 5px; color:#fff;'>";
  277. _html+= " <div id='planTip' style='float:left;'><div style='width:20px;height:8px;background:"+_data.topColor[0]+";border:1px solid "+_data.topColor[1]+"; float:left; margin:7px 5px 0 0 ;'></div><div style='float:left;'>"+_tipdata.planTitle+"</div></div>";
  278. _html+= " <div id='lineOneTip' style='float:left;'><div style='width:20px;height:3px;background:"+_data.topColor[2]+"; float:left; margin:10px 5px 0 15px ;'></div><div style='float:left;'>"+_tipdata.planLineOne+"</div></div>";
  279. _html+= " <div id='lineTwoTip' style='float:left;'><div style='width:20px;height:3px;background:"+_data.topColor[3]+"; float:left; margin:10px 5px 0 15px ;'></div><div style='float:left;'>"+_tipdata.planLineTwo+"</div></div></div>";
  280. // 绘制图表。
  281. var myChart = echarts.init(document.getElementById(id));
  282. //头部div显示位置
  283. $("#topTitle").empty();
  284. $(myChart._dom.childNodes[0]).after(_html);
  285. //显示隐藏计划值tip
  286. if(_tipdata.topPlanTipIsTrue){
  287. $("#planTip").css("display","block");
  288. }else{
  289. $("#planTip").css("display","none");
  290. };
  291. //tip居中处理
  292. var marginLeft=$("#topTitle").width()/2;
  293. $("#topTitle").css("margin-left","-"+marginLeft+"px");
  294. //echar配置
  295. var option = {
  296. backgroundColor: _data.backgroundColor,
  297. legend: {
  298. show:false
  299. },
  300. tooltip: {
  301. show: false,
  302. triggerOn: "none"
  303. },
  304. grid: {
  305. left: '200',
  306. right: '5%',
  307. bottom: '5%',
  308. containLabel: false
  309. },
  310. xAxis: {
  311. type: 'value',
  312. min: 0,
  313. max: 50,
  314. boundaryGap: true,
  315. axisLabel: {
  316. show: false,
  317. textStyle: {
  318. color:"#fff"
  319. }
  320. },
  321. axisLine: {
  322. show: false
  323. },
  324. axisTick: {
  325. show: false
  326. },
  327. splitLine: {
  328. show: false
  329. }
  330. },
  331. yAxis: {
  332. type: 'category',
  333. inverse: true,
  334. boundaryGap: true,
  335. axisLine: {
  336. show: false,
  337. },
  338. axisTick: {
  339. show: false,
  340. alignWithLabel: false
  341. },
  342. axisLabel: {
  343. show: true,
  344. margin:155.9,
  345. backgroundColor:"rgba(50,50,50,0.3)",
  346. textStyle: {
  347. color:"#fff"
  348. }
  349. },
  350. axisPointer: {
  351. show: true,
  352. type: "shadow",
  353. label: {
  354. show: true
  355. }
  356. },
  357. triggerEvent: true, //坐标轴的标签是否响应和触发鼠标事件,默认不响应
  358. data:[]
  359. },
  360. series: [
  361. {
  362. name: '数据1',
  363. type: 'line',
  364. smooth: false,
  365. symbol: 'circle',
  366. symbolSize: 8,
  367. itemStyle:{
  368. color:"#18daff"
  369. },
  370. lineStyle: {
  371. normal: {
  372. width: 1,
  373. color:"#18daff",
  374. shadowColor: 'rgba(0,0,0,0.4)',
  375. shadowBlur: 10,
  376. shadowOffsetY: 10
  377. }
  378. },
  379. connectNulls: false, //开启连接空数据
  380. label: {
  381. normal: {
  382. show: true,
  383. color:"#18daff",
  384. formatter: '{c}',
  385. rich:{},
  386. position: 'left' //值显示
  387. }
  388. },
  389. markArea: {
  390. data: [
  391. [{
  392. xAxis: ''
  393. }, {
  394. xAxis: '',
  395. itemStyle: {
  396. color: {
  397. type: 'linear',
  398. x: 0,
  399. y: 0,
  400. x2: 1,
  401. y2: 0,
  402. colorStops: [{
  403. offset: 0,
  404. color: '' // 0% 处的颜色
  405. }, {
  406. offset: 1,
  407. color: '' // 100% 处的颜色
  408. }],
  409. globalCoord: false // 缺省为 false
  410. }
  411. }
  412. }
  413. ],
  414. [{
  415. xAxis: ''
  416. }, {
  417. xAxis: '',
  418. itemStyle: {
  419. color: {
  420. type: 'linear',
  421. x: 0,
  422. y: 0,
  423. x2: 1,
  424. y2: 0,
  425. colorStops: [{
  426. offset: 0,
  427. color: '' // 0% 处的颜色
  428. }, {
  429. offset: 1,
  430. color: '' // 100% 处的颜色
  431. }],
  432. globalCoord: false // 缺省为 false
  433. }
  434. }
  435. }
  436. ],
  437. [{
  438. xAxis: ''
  439. }, {
  440. xAxis: '',
  441. itemStyle: {
  442. color: {
  443. type: 'linear',
  444. x: 0,
  445. y: 0,
  446. x2: 1,
  447. y2: 0,
  448. colorStops: [{
  449. offset: 0,
  450. color: '' // 0% 处的颜色
  451. }, {
  452. offset: 1,
  453. color: '' // 100% 处的颜色
  454. }],
  455. globalCoord: false // 缺省为 false
  456. }
  457. }
  458. }
  459. ],
  460. [{
  461. xAxis: ''
  462. }, {
  463. xAxis: '',
  464. itemStyle: {
  465. color: {
  466. type: 'linear',
  467. x: 0,
  468. y: 0,
  469. x2: 1,
  470. y2: 0,
  471. colorStops: [{
  472. offset: 0,
  473. color: '' // 0% 处的颜色
  474. }, {
  475. offset: 1,
  476. color: '' // 100% 处的颜色
  477. }],
  478. globalCoord: false // 缺省为 false
  479. }
  480. }
  481. }],
  482. [{
  483. xAxis: ''
  484. }, {
  485. xAxis: '',
  486. itemStyle: {
  487. color: {
  488. type: 'linear',
  489. x: 0,
  490. y: 0,
  491. x2: 1,
  492. y2: 0,
  493. colorStops: [{
  494. offset: 0,
  495. color: '' // 0% 处的颜色
  496. }, {
  497. offset: 1,
  498. color: '' // 100% 处的颜色
  499. }],
  500. globalCoord: false // 缺省为 false
  501. }
  502. }
  503. }],
  504. [{
  505. xAxis: ''
  506. }, {
  507. xAxis: '',
  508. itemStyle: {
  509. color: {
  510. type: 'linear',
  511. x: 0,
  512. y: 0,
  513. x2: 1,
  514. y2: 0,
  515. colorStops: [{
  516. offset: 0,
  517. color: '' // 0% 处的颜色
  518. }, {
  519. offset: 1,
  520. color: '' // 100% 处的颜色
  521. }],
  522. globalCoord: false // 缺省为 false
  523. }
  524. }
  525. }],
  526. ]
  527. },
  528. markLine: {
  529. silent: true,
  530. symbolSize: 0,
  531. label: {
  532. position: "start",
  533. formatter: function(params) {
  534. return ""
  535. }
  536. },
  537. lineStyle: {
  538. type: "solid",
  539. color: "rgba(250,250,250,0.3)",
  540. width: "20"
  541. },
  542. data: [],
  543. rich:{
  544. blue: {color: 'blue'},
  545. green: {color: 'green'},
  546. red: {color: 'red'},
  547. white: {color: 'white'}
  548. }
  549. },
  550. data:[]
  551. },
  552. {
  553. name: '数据2',
  554. type: 'line',
  555. symbol: 'circle',
  556. smooth: false,
  557. symbolSize: 8,
  558. itemStyle:{
  559. color:"#fffa4a"
  560. },
  561. lineStyle: {
  562. normal: {
  563. width: 1,
  564. color:"#fffa4a",
  565. shadowColor: 'rgba(0,0,0,0.4)',
  566. shadowBlur: 10,
  567. shadowOffsetY: 10
  568. }
  569. },
  570. connectNulls: false, //开启连接空数据
  571. label: {
  572. normal: {
  573. show: true,
  574. fontSize: 8,
  575. formatter: "{c}",
  576. rich:{},
  577. position: 'right' //值显示
  578. }
  579. },
  580. markLine: {
  581. silent: true,
  582. symbolSize: 0,
  583. label: {
  584. position: "start",
  585. formatter: function(params) {
  586. var value = params.value;
  587. return value
  588. }
  589. },
  590. lineStyle: {
  591. type: "solid",
  592. width: "0",
  593. curveness: 1,
  594. color:"#fff"
  595. },
  596. data: []
  597. },
  598. data:[]
  599. },
  600. {
  601. name:"实际值",
  602. type: 'line',
  603. symbol: 'circle',
  604. smooth: false,
  605. symbolSize: 0.00000001,
  606. itemStyle:{
  607. color:"rgba(0,0,0,0)"
  608. },
  609. label: {
  610. normal: {
  611. show: true,
  612. color:"green",
  613. formatter: '{c}',
  614. rich:{},
  615. position: 'inside' //值显示
  616. }
  617. },
  618. data:[]
  619. },
  620. {
  621. name:"增长",
  622. type: 'line',
  623. symbol: 'circle',
  624. smooth: false,
  625. symbolSize: 0.00000001,
  626. itemStyle:{
  627. color:"rgba(0,0,0,0)"
  628. },
  629. label: {
  630. normal: {
  631. show: true,
  632. color:"#fff",
  633. formatter: '{c}',
  634. rich:{},
  635. position: 'inside' //值显示
  636. }
  637. },
  638. data:[]
  639. }
  640. ]
  641. };
  642. option.yAxis.data=_data.yAxis.data;
  643. option.xAxis.min=_data.xAxis.min;
  644. option.xAxis.max=_data.xAxis.max;
  645. //处理Y轴多列文字显示问题
  646. option.series[2].data=_data.yAxisText1;
  647. option.series[3].data=_data.yAxisText2;
  648. //折线图1
  649. option.series[0].name=_tipdata.planLineOne;
  650. option.series[0].data=_data.seriesData[0].data;
  651. option.series[0].itemStyle.color=_data.seriesData[0].lineColor;
  652. option.series[0].lineStyle.normal.color=_data.seriesData[0].lineColor;
  653. option.series[0].markLine.data=_data.yAxis.yAxisUnit;
  654. for(var j=0;j<_data.xAxis.markArea.data.length;j++){
  655. var leng=_data.xAxis.markArea.data.length;
  656. var _nwIsTrue=_data.xAxis.markArea.nwIsTrue
  657. option.series[0].markArea.data[j][0].xAxis=_data.xAxis.markArea.data[j].startNum;
  658. option.series[0].markArea.data[j][1].xAxis=_data.xAxis.markArea.data[j].endNum;
  659. option.series[0].markArea.data[j][1].itemStyle.color.colorStops[0].color=_data.xAxis.markArea.data[j].startColor;
  660. option.series[0].markArea.data[j][1].itemStyle.color.colorStops[1].color=_data.xAxis.markArea.data[j].endColor;
  661. //是否显示绿色标域的边框
  662. if(_nwIsTrue){
  663. option.series[0].markArea.data[leng-1][1].itemStyle.color.colorStops[0].color=_data.xAxis.markArea.data[j].endColor;
  664. option.series[0].markArea.data[leng-1][1].itemStyle.color.colorStops[1].color=_data.xAxis.markArea.data[j].endColor;
  665. option.series[0].markArea.data[leng-1][1].itemStyle.borderWidth="3";
  666. option.series[0].markArea.data[leng-1][1].itemStyle.borderColor=_data.xAxis.markArea.borderColor;
  667. }
  668. }
  669. //折线图2
  670. option.series[1].name=_tipdata.planLineTwo;
  671. option.series[1].data=_data.seriesData[1].data;
  672. option.series[1].itemStyle.color=_data.seriesData[1].lineColor;
  673. option.series[1].lineStyle.normal.color=_data.seriesData[1].lineColor;
  674. option.series[1].markLine.data=data.xAxis.markAreaData;
  675. option.series[1].markLine.label.formatter=function(params){
  676. var value = params.value;
  677. var y_val0=_data.xAxis.markArea.data[0].endNum;
  678. var y_text0=_data.xAxis.markArea.data[0].text;
  679. var y_val1=_data.xAxis.markArea.data[1].endNum;
  680. var y_text1=_data.xAxis.markArea.data[1].text;
  681. var _val0=_data.xAxis.markArea.data[2].endNum;
  682. var _text0=_data.xAxis.markArea.data[2].text;
  683. var _val1=_data.xAxis.markArea.data[3].endNum;
  684. var _text1=_data.xAxis.markArea.data[3].text;
  685. var _val2=_data.xAxis.markArea.data[4].endNum;
  686. var _text2=_data.xAxis.markArea.data[4].text;
  687. var _val3=_data.xAxis.markArea.data[5].endNum;
  688. var _text3=_data.xAxis.markArea.data[5].text;
  689. //处理顶部标文字
  690. if(value == y_val0){
  691. value = "{white|"+y_text0+"}"
  692. }else if(value == y_val1){
  693. value = "{white|"+y_text1+"}"
  694. }else if(value == _val0) {
  695. value = "{blue|"+_text0+"}"
  696. } else if(value == _val1) {
  697. value = "{green|"+_text1+"}"
  698. } else if(value ==_val2) {
  699. value = "{red|"+_text2+"}"
  700. } else if(value == _val3) {
  701. value = "{white|"+_text3+"}"
  702. }
  703. return value
  704. }
  705. option.series[1].markLine.label.rich={
  706. blue: {color: 'blue'},
  707. green: {color: 'green'},
  708. red: {color: 'red'},
  709. white: {color: 'white'}
  710. }
  711. //可通过谋属性或者值来格式化点上的文字,颜色,位置
  712. if(true){
  713. for(var n=0;n<2;n++){
  714. var val1=[],val2=[];
  715. //处理折线1上的点的大小,颜色问题
  716. option.series[0].label.normal.position="left";
  717. option.series[0].data.forEach(function(value,index,array){
  718. // console.log(value)
  719. var _val=value.value;
  720. val1.push(_val);
  721. var _symbolSize=value.symbolSize;
  722. if(_val>0 && _val<5 && _symbolSize!=0){
  723. value.itemStyle.color="red";
  724. value.label.normal.position="left";
  725. value.symbolSize=15;
  726. }else if(_val>5 && _val<25 && _symbolSize!=0){
  727. }else if(_val>25 && _val<40 && _symbolSize!=0){
  728. }else if(_val>40 && _val<50 && _symbolSize!=0){
  729. value.itemStyle.color="green";
  730. value.label.normal.position="right";
  731. value.symbolSize=15
  732. }
  733. });
  734. //处理折线2上的点的大小,颜色问题
  735. option.series[1].label.normal.position="right";
  736. option.series[1].data.forEach(function(value,index,array){
  737. var _val=value.value;
  738. val2.push(_val);
  739. var _symbolSize=value.symbolSize;
  740. if(_val>0 && _val<5 && _symbolSize!=0){
  741. value.itemStyle.color="red";
  742. value.label.normal.position="top";
  743. value.symbolSize=15;
  744. }else if(_val>5 && _val<25 && _symbolSize!=0){
  745. }else if(_val>25 && _val<40 && _symbolSize!=0){
  746. }else if(_val>40 && _val<50 && _symbolSize!=0){
  747. value.itemStyle.color="green";
  748. value.label.normal.position="right";
  749. value.symbolSize=15
  750. }
  751. });
  752. //处理2组数据点上文字左右的排布问题
  753. var _length=val1.length
  754. if(_length==val2.length){
  755. for(var i = 0; i < _length; i++) {
  756. if(val1[i] <= val2[i]) {
  757. option.series[0].data[i].label.normal.position="left";
  758. if(option.series[0].data[i].itemStyle.color=="red"){
  759. option.series[0].data[i].label.normal.position="right";
  760. }
  761. option.series[1].data[i].label.normal.position="right";
  762. }
  763. else {
  764. option.series[0].data[i].label.normal.position="right";
  765. option.series[1].data[i].label.normal.position="left";
  766. }
  767. }
  768. }
  769. //格式化点上文字描述
  770. option.series[n].label.normal.formatter=function(params){
  771. //console.log(params.data)
  772. var _val=params.value;
  773. var _symbolSize=params.data.symbolSize;
  774. var _ranking=params.data.ranking;
  775. var _Static=params.data.Static;
  776. var _Percentage=params.data.Percentage;
  777. var text = "";
  778. var _color="";
  779. if(_Static==0){
  780. _Static="↓"
  781. _color="red";
  782. }else{
  783. _Static="↑"
  784. _color="green";
  785. };
  786. if(_symbolSize != 0) {
  787. text = "{white|"+_ranking+"} {blue|"+_val+"}\n{"+_color+"|"+_Static+_Percentage+"}"
  788. }
  789. return text
  790. };
  791. option.series[n].label.normal.rich={
  792. blue: {color: 'blue'},
  793. green: {color: 'green'},
  794. red: {color: 'red'},
  795. white: {color: 'white'}
  796. };
  797. }
  798. }
  799. //格式化Y轴多列文字
  800. option.series[2].label.normal.formatter=function(params){
  801. var _val = params.data.value;
  802. var _text = params.data.text;
  803. var _upIsTrue = params.data.upIsTrue;
  804. var _color = "green";
  805. if(_upIsTrue){
  806. _color = "green";
  807. }else{
  808. _color = "red";
  809. };
  810. _text = "{"+_color+"|"+_text+"}"
  811. return _text
  812. }
  813. option.series[2].label.normal.rich={
  814. green: {color: 'green'},
  815. red: {color: 'red'}
  816. };
  817. option.series[3].label.normal.formatter=function(params){
  818. var _val = params.data.value;
  819. var _text = params.data.text;
  820. return _text
  821. }
  822. //绘制图
  823. myChart.setOption(option, true);
  824. //点击事件
  825. // myChart.on('click', function (params) {
  826. // //点击Y轴上的文字 注意给对应的Y轴开启:triggerEvent:true
  827. // if(params.componentType=="yAxis" && params.yAxisIndex=="0"){
  828. // if(params.value=="单位00"){
  829. // option.series[0].data=[34,32,null,33,35,null,39,33,38,null, 39,35]
  830. // }else{
  831. // option.series[0].data=[14,12,null,13,15,null,19,13,18,null, 19,15]
  832. // }
  833. // option.yAxis.axisPointer.value=params.value;
  834. // myChart.setOption(option,true);
  835. // }
  836. // });
  837. }
  838. </script>

DOME下载

竖着的折线图(Y轴多列文字).rar

本文为原创文章,转载请附上原文链接!