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

247 lines
4.5 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 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. let sum = 0
  142. serie.data.forEach(n => {
  143. sum += n
  144. })
  145. sum = (sum / serie.data.length).toFixed(2)
  146. // 配置 ECharts
  147. const option = {
  148. backgroundColor: '#1B263B',
  149. title: {
  150. text: `${serie.name} 近7日铝均价${sum} 今日铝价${serie.data[serie.data.length - 1].toFixed(2)}`,
  151. right: '10%',
  152. top: '10%',
  153. textStyle: {
  154. color: '#fff',
  155. fontSize: 12
  156. }
  157. },
  158. // legend: {
  159. // data: ['长江铝现货', '国内现货价', '国外现货价'],
  160. // textStyle: {
  161. // color: '#fff',
  162. // fontSize : '9px'
  163. // },
  164. // },
  165. tooltip: {
  166. trigger: 'axis',
  167. formatter: '{c0}',
  168. backgroundColor: '#3A506B',
  169. textStyle: {
  170. color: '#fff',
  171. }
  172. },
  173. grid: {
  174. left: '58px',
  175. right: '1%',
  176. bottom: '15%'
  177. },
  178. xAxis: {
  179. type: 'category',
  180. data: this.dates[this.index],
  181. axisLine: {
  182. lineStyle: {
  183. color: '#fff'
  184. },
  185. },
  186. axisLabel: {
  187. color: '#fff',
  188. fontSize : '10px',
  189. },
  190. },
  191. yAxis: {
  192. type: 'value',
  193. min : function(value){
  194. return value.min;
  195. },
  196. axisLine: {
  197. lineStyle: {
  198. color: '#fff'
  199. }
  200. },
  201. axisLabel: {
  202. color: '#fff',
  203. formatter: function(value) {
  204. return value;
  205. }
  206. }
  207. },
  208. series: [this.series[this.index]]
  209. };
  210. this.myChart.setOption(option);
  211. },
  212. clickTabs(e){
  213. console.log(e);
  214. this.index = e.index
  215. this.initChart()
  216. },
  217. },
  218. }
  219. </script>
  220. <style scoped lang="scss">
  221. .visualization{
  222. background-color: #1B263B;
  223. padding: 20rpx 0;
  224. .chartContainer{
  225. width: 100%;
  226. height: 300px;
  227. }
  228. }
  229. </style>