铝交易,微信公众号
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.

236 lines
4.3 KiB

4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 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. data.length = 4
  119. for(let i = 0;i < data.length;i++){
  120. this.dates.push(data[i].map(n => this.$dayjs(n.priceDate)
  121. .format('MM-DD')))
  122. }
  123. this.series.forEach((s, i) => {
  124. if(data[i]){
  125. s.data = data[i].map(n => n.price)
  126. }
  127. })
  128. const chartContainer = this.$refs.chartContainer;
  129. if (!chartContainer) {
  130. console.error("Chart container not found");
  131. return;
  132. }
  133. this.myChart = echarts.init(chartContainer);
  134. this.initChart()
  135. }
  136. })
  137. },
  138. initChart(data) {
  139. var that = this;
  140. let serie = this.series[this.index]
  141. // 配置 ECharts
  142. const option = {
  143. backgroundColor: '#1B263B',
  144. title: {
  145. text: `${serie.name} ${serie.data[serie.data.length - 1].toFixed(4)}`,
  146. right: '10%',
  147. top: '10%',
  148. textStyle: {
  149. color: '#fff',
  150. fontSize: 12
  151. }
  152. },
  153. // legend: {
  154. // data: ['长江铝现货', '国内现货价', '国外现货价'],
  155. // textStyle: {
  156. // color: '#fff',
  157. // fontSize : '9px'
  158. // },
  159. // },
  160. tooltip: {
  161. trigger: 'axis',
  162. formatter: '{c0}',
  163. backgroundColor: '#3A506B',
  164. textStyle: {
  165. color: '#fff',
  166. }
  167. },
  168. grid: {
  169. left: '58px',
  170. right: '1%',
  171. bottom: '15%'
  172. },
  173. xAxis: {
  174. type: 'category',
  175. data: this.dates[this.index],
  176. axisLine: {
  177. lineStyle: {
  178. color: '#fff'
  179. },
  180. },
  181. axisLabel: {
  182. color: '#fff',
  183. fontSize : '10px',
  184. }
  185. },
  186. yAxis: {
  187. type: 'value',
  188. axisLine: {
  189. lineStyle: {
  190. color: '#fff'
  191. }
  192. },
  193. axisLabel: {
  194. color: '#fff',
  195. formatter: function(value) {
  196. return value;
  197. }
  198. }
  199. },
  200. series: [this.series[this.index]]
  201. };
  202. this.myChart.setOption(option);
  203. },
  204. clickTabs(e){
  205. console.log(e);
  206. this.index = e.index
  207. this.initChart()
  208. },
  209. },
  210. }
  211. </script>
  212. <style scoped lang="scss">
  213. .visualization{
  214. background-color: #1B263B;
  215. padding: 20rpx 0;
  216. .chartContainer{
  217. width: 100%;
  218. height: 300px;
  219. }
  220. }
  221. </style>