line-echarts.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <view class="charts-box">
  3. <qiun-data-charts :type="echartsData.chartType" :opts="opts" :chartData="chartData" />
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. echartsData: Object
  10. },
  11. data() {
  12. return {
  13. chartData: {},
  14. //您可以通过修改 config-ucharts.js 文件中下标为 ['line'] 的节点来配置全局默认参数,如都是默认参数,此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
  15. opts: {
  16. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
  17. "#ea7ccc"
  18. ],
  19. padding: [15, 10, 0, 15],
  20. enableScroll: false,
  21. legend: {},
  22. xAxis: {
  23. disableGrid: true
  24. },
  25. yAxis: {
  26. gridType: "dash",
  27. dashLength: 2
  28. },
  29. extra: {
  30. line: {
  31. type: "curve",
  32. width: 2,
  33. activeType: "hollow"
  34. }
  35. }
  36. }
  37. };
  38. },
  39. mounted() {
  40. this.getServerData();
  41. },
  42. methods: {
  43. getServerData() {
  44. const chartData = this.echartsData.chartItemList
  45. const timeData = chartData[0].valueTimeList
  46. const time = timeData.map(item => {
  47. return item.substring(0, 4)
  48. })
  49. const series = chartData.map(item => {
  50. return {
  51. name: item.id,
  52. data: item.valueList
  53. }
  54. })
  55. let res = {
  56. categories: time,
  57. series: series
  58. };
  59. this.chartData = JSON.parse(JSON.stringify(res));
  60. },
  61. }
  62. };
  63. </script>
  64. <style scoped>
  65. /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
  66. .charts-box {
  67. width: 100%;
  68. height: 540rpx;
  69. }
  70. </style>