铝交易,微信公众号
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
4.2 KiB

7 months ago
  1. <template>
  2. <view class="visualization">
  3. <uv-tabs :list="tabs"
  4. lineColor="#fff"
  5. :inactiveStyle="{color : '#aaa', fontSize : '24rpx'}"
  6. :activeStyle="{color : '#fff', fontSize : '24rpx'}"
  7. @click="clickTabs"></uv-tabs>
  8. <div class="chartContainer"
  9. ref="chartContainer"></div>
  10. </view>
  11. </template>
  12. <script>
  13. import * as echarts from 'echarts';
  14. export default {
  15. data() {
  16. return {
  17. tabs : [
  18. {
  19. name : '长江现货铝均价',
  20. },
  21. {
  22. name : '国内现货铝均价',
  23. },
  24. {
  25. name : '国外现货铝均价',
  26. },
  27. {
  28. name : '伦敦铝均价',
  29. },
  30. ],
  31. series : [
  32. {
  33. name: '长江现货铝均价',
  34. type: 'line',
  35. data: [],
  36. smooth: true,
  37. symbol: 'circle',
  38. symbolSize: 8,
  39. itemStyle: {
  40. color: '#4ECDC4'
  41. },
  42. lineStyle: {
  43. color: '#4ECDC4',
  44. width: 2
  45. },
  46. areaStyle: {
  47. color: '#4ECDC422'
  48. },
  49. },
  50. {
  51. name: '国内现货铝均价',
  52. type: 'line',
  53. data: [],
  54. smooth: true,
  55. symbol: 'circle',
  56. symbolSize: 8,
  57. itemStyle: {
  58. color: '#ff0'
  59. },
  60. lineStyle: {
  61. color: '#ff0',
  62. width: 2
  63. },
  64. areaStyle: {
  65. color: '#ffff0022'
  66. },
  67. },
  68. {
  69. name: '国外现货铝均价',
  70. type: 'line',
  71. data: [],
  72. smooth: true,
  73. symbol: 'circle',
  74. symbolSize: 8,
  75. itemStyle: {
  76. color: '#cd0000'
  77. },
  78. lineStyle: {
  79. color: '#cd0000',
  80. width: 2
  81. },
  82. areaStyle: {
  83. color: '#cd000022'
  84. },
  85. },
  86. {
  87. name: '伦敦铝均价',
  88. type: 'line',
  89. data: [],
  90. smooth: true,
  91. symbol: 'circle',
  92. symbolSize: 8,
  93. itemStyle: {
  94. color: '#c800ff'
  95. },
  96. lineStyle: {
  97. color: '#c800ff',
  98. width: 2
  99. },
  100. areaStyle: {
  101. color: '#c800ff22'
  102. },
  103. },
  104. ],
  105. dates : [],
  106. index : 0,
  107. myChart : null,
  108. }
  109. },
  110. created() {
  111. this.getData()
  112. },
  113. methods: {
  114. getData(){
  115. this.$api("alpriceNew", res => {
  116. if(res.code == 200){
  117. let data = res.result
  118. this.dates = data[0].map(n => this.$dayjs(n.priceDate)
  119. .format('MM-DD'))
  120. this.series.forEach((s, i) => {
  121. if(data[i]){
  122. s.data = data[i].map(n => n.price)
  123. }
  124. })
  125. const chartContainer = this.$refs.chartContainer;
  126. if (!chartContainer) {
  127. console.error("Chart container not found");
  128. return;
  129. }
  130. this.myChart = echarts.init(chartContainer);
  131. this.initChart()
  132. }
  133. })
  134. },
  135. initChart(data) {
  136. var that = this;
  137. let serie = this.series[this.index]
  138. // 配置 ECharts
  139. const option = {
  140. backgroundColor: '#1B263B',
  141. title: {
  142. text: `${serie.name} ${serie.data[serie.data.length - 1].toFixed(4)}`,
  143. right: '10%',
  144. top: '10%',
  145. textStyle: {
  146. color: '#fff',
  147. fontSize: 12
  148. }
  149. },
  150. // legend: {
  151. // data: ['长江铝现货', '国内现货价', '国外现货价'],
  152. // textStyle: {
  153. // color: '#fff',
  154. // fontSize : '9px'
  155. // },
  156. // },
  157. tooltip: {
  158. trigger: 'axis',
  159. formatter: '{c0}',
  160. backgroundColor: '#3A506B',
  161. textStyle: {
  162. color: '#fff',
  163. }
  164. },
  165. grid: {
  166. left: '58px',
  167. right: '1%',
  168. bottom: '15%'
  169. },
  170. xAxis: {
  171. type: 'category',
  172. data: this.dates,
  173. axisLine: {
  174. lineStyle: {
  175. color: '#fff'
  176. },
  177. },
  178. axisLabel: {
  179. color: '#fff',
  180. fontSize : '10px',
  181. }
  182. },
  183. yAxis: {
  184. type: 'value',
  185. axisLine: {
  186. lineStyle: {
  187. color: '#fff'
  188. }
  189. },
  190. axisLabel: {
  191. color: '#fff',
  192. formatter: function(value) {
  193. return value;
  194. }
  195. }
  196. },
  197. series: [this.series[this.index]]
  198. };
  199. this.myChart.setOption(option);
  200. },
  201. clickTabs(e){
  202. console.log(e);
  203. this.index = e.index
  204. this.initChart()
  205. },
  206. },
  207. }
  208. </script>
  209. <style scoped lang="scss">
  210. .visualization{
  211. background-color: #1B263B;
  212. padding: 20rpx 0;
  213. .chartContainer{
  214. width: 100%;
  215. height: 300px;
  216. }
  217. }
  218. </style>