line-echarts.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="charts-box">
  3. <qiun-data-charts :type="echartsData.chartType" :opts="opts" :chartData="chartData" :ontouch="true" />
  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: true,
  21. legend: {},
  22. xAxis: {
  23. disableGrid: true,
  24. scrollShow: true,
  25. itemCount: 10
  26. },
  27. yAxis: {
  28. gridType: "dash",
  29. dashLength: 2
  30. },
  31. extra: {
  32. line: {
  33. type: "curve",
  34. width: 2,
  35. activeType: "hollow"
  36. }
  37. }
  38. }
  39. };
  40. },
  41. mounted() {
  42. this.getServerData();
  43. },
  44. methods: {
  45. getServerData() {
  46. const chartData = this.echartsData.chartItemList
  47. const timeData = chartData[0].valueTimeList
  48. const time = timeData.map(item => {
  49. return item.substring(0, 4)
  50. })
  51. const series = chartData.map(item => {
  52. return {
  53. name: item.id,
  54. data: item.valueList
  55. }
  56. })
  57. let res = {
  58. categories: time,
  59. series: series
  60. };
  61. this.chartData = JSON.parse(JSON.stringify(res));
  62. },
  63. }
  64. };
  65. </script>
  66. <style scoped>
  67. /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
  68. .charts-box {
  69. width: 100%;
  70. height: 540rpx;
  71. }
  72. </style>