time-sharing.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <div id="chart122" :prop="config" :change:prop="highstock.changeConfig" class="chart-box"></div>
  3. </template>
  4. <script>
  5. import { mapState } from "vuex";
  6. export default {
  7. props: {
  8. tradeList: {
  9. default() {
  10. return [];
  11. },
  12. type: Array,
  13. required: false,
  14. },
  15. query: {
  16. default: {},
  17. type: Object,
  18. required: false,
  19. },
  20. },
  21. computed: {
  22. ...mapState({
  23. serveTheme: "theme",
  24. }),
  25. },
  26. watch: {},
  27. data() {
  28. return {
  29. config: {},
  30. };
  31. },
  32. methods: {
  33. resetData(){
  34. this.config = '';
  35. this.$nextTick(()=>{
  36. this.config = {
  37. type:'resetList',
  38. list:this.tradeList,
  39. date:new Date()
  40. }
  41. })
  42. },
  43. addPoint(data){
  44. this.config = {
  45. type:'addPoint',
  46. point:data,
  47. date:new Date()
  48. }
  49. },
  50. getConfig() {
  51. return {
  52. type: "initPage",
  53. list: this.tradeList,
  54. theme:this.serveTheme
  55. };
  56. },
  57. },
  58. created() {
  59. this.config = this.getConfig();
  60. },
  61. };
  62. </script>
  63. <script module="highstock" lang="renderjs">
  64. import highstock from "highcharts/highstock";
  65. export default {
  66. computed: {
  67. list() {
  68. return this.chartTradList.map((item) => {
  69. return [item.ts, item.price*1];
  70. });
  71. },
  72. },
  73. watch: {},
  74. data() {
  75. return {
  76. chart: undefined,
  77. chartTradList:[],
  78. theme:'light'
  79. };
  80. },
  81. methods: {
  82. changeConfig(config){
  83. this.task(config)
  84. },
  85. task(config){
  86. switch (config.type) {
  87. case 'resetList':
  88. this.chartTradList = config.list;
  89. this.setData(this.list)
  90. break;
  91. case 'addPoint':
  92. this.webAddPoint(config.point)
  93. break;
  94. case 'initPage':
  95. this.chartTradList = config.list;
  96. this.theme = config.theme;
  97. break;
  98. default:
  99. break;
  100. }
  101. },
  102. intiChart($box) {
  103. highstock.setOptions({
  104. global: {
  105. timezoneOffset: -8 * 60,
  106. },
  107. });
  108. this.chart = highstock.stockChart($box, {
  109. chart: {
  110. marginTop: 0,
  111. // marginLeft: 0,
  112. marginBottom: 20,
  113. padding: 0,
  114. panning: false, //禁用放大
  115. pinchType: "", //禁用手势操作
  116. zoomType: "",
  117. panKey: "shift",
  118. backgroundColor: "transparent",
  119. borderColor: "transparent",
  120. borderWidth: "1",
  121. plotBackgroundColor: "transparent",
  122. Point: {
  123. visible: !1,
  124. },
  125. },
  126. rangeSelector: {
  127. enabled: false,
  128. },
  129. navigator: {
  130. enabled: false,
  131. },
  132. scrollbar: {
  133. enabled: false,
  134. },
  135. exporting: {
  136. enabled: !0,
  137. },
  138. credits: {
  139. enabled: !1,
  140. },
  141. mapNavigation: {
  142. enabled: !1,
  143. enableButtons: !1,
  144. },
  145. navigation: {
  146. enabled: !1,
  147. buttonOptions: {},
  148. },
  149. title: {
  150. text: null,
  151. },
  152. yAxis: {
  153. gridLineWidth: 1,
  154. tickWidth: 0,
  155. tickColor: "#1E2E3F",
  156. tickAmount: 7,
  157. // lineWidth: 1,
  158. lineColor: "#1E2E3F",
  159. labels: {
  160. align: "center",
  161. x: 0,
  162. style: {
  163. color: this.theme=='light'?"#333":"#dcdee0",
  164. fontSize: "8px",
  165. },
  166. useHTML: !0,
  167. formatter: (ev) => {
  168. return this.nFormatter(ev.value, 3);
  169. },
  170. },
  171. opposite: false,
  172. gridLineColor: "transparent",
  173. },
  174. xAxis: {
  175. type: "datetime",
  176. dateTimeLabelFormats: {
  177. millisecond: "%H:%M:%S.%L",
  178. second: "%H:%M:%S",
  179. minute: "%H:%M",
  180. hour: "%H:%M",
  181. day: "%m-%d",
  182. week: "%m-%d",
  183. month: "%Y-%m",
  184. year: "%Y",
  185. },
  186. tickWidth: 0,
  187. lineWidth: "0",
  188. tickLength: 0,
  189. labels: {
  190. style: {
  191. color: this.theme=='light'?"#333":"#dcdee0",
  192. fontSize: "10px",
  193. },
  194. y: 10,
  195. },
  196. },
  197. tooltip: {
  198. enabled: false,
  199. dateTimeLabelFormats: {
  200. millisecond: "%H:%M:%S.%L",
  201. second: "%H:%M:%S",
  202. minute: "%H:%M",
  203. hour: "%H:%M",
  204. day: "%Y-%m-%d",
  205. week: "%m-%d",
  206. month: "%Y-%m",
  207. year: "%Y",
  208. },
  209. },
  210. legend: {
  211. enabled: !1,
  212. },
  213. plotOptions: {
  214. areaspline: {
  215. allowPointSelect:false,
  216. fillColor: {
  217. linearGradient: {
  218. x1: 0,
  219. y1: 0,
  220. x2: 0,
  221. y2: 1,
  222. },
  223. stops: [
  224. [0, "rgba(192,96,194,.58)"],
  225. [1, "rgba(90,99,251,.13)"],
  226. ],
  227. },
  228. marker: {
  229. radius: 2,
  230. },
  231. lineWidth: 2,
  232. threshold: null,
  233. },
  234. },
  235. series: [
  236. {
  237. marker: {
  238. radius: 0,
  239. lineWidth: 0,
  240. lineColor: "#fba845",
  241. fillColor: "#fba845",
  242. states: {},
  243. },
  244. type: "areaspline",
  245. name: "",
  246. data: this.list,
  247. color: {
  248. linearGradient:{
  249. x1:'0%',
  250. y1:'0%',
  251. x2:'100%',
  252. y2:'100%'
  253. },
  254. stops:[
  255. [0, '#C060C2'],
  256. [1, '#5A63FB'],
  257. ]
  258. },
  259. },
  260. ],
  261. });
  262. },
  263. nFormatter(num, digits) {
  264. const si = [
  265. { value: 1, symbol: "" },
  266. { value: 1e3, symbol: "K" },
  267. { value: 1e6, symbol: "M" },
  268. { value: 1e9, symbol: "G" },
  269. { value: 1e12, symbol: "T" },
  270. { value: 1e15, symbol: "P" },
  271. { value: 1e18, symbol: "E" },
  272. ];
  273. const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
  274. let i;
  275. for (i = si.length - 1; i > 0; i--) {
  276. if (num >= si[i].value) {
  277. break;
  278. }
  279. }
  280. return (
  281. (num / si[i].value).toFixed(digits).replace(rx, "$1") + si[i].symbol
  282. );
  283. },
  284. setData(arr) {
  285. if(this.chart) this.chart.series[0].setData(arr);
  286. },
  287. webAddPoint(obj){
  288. if(this.chart) this.chart.series[0].addPoint(obj,true,true)
  289. }
  290. },
  291. mounted() {
  292. this.task(this.config)
  293. this.intiChart(document.getElementById("chart122"));
  294. },
  295. destroyed() {},
  296. };
  297. </script>
  298. <style lang="scss" scoped>
  299. .chart-box {
  300. height: 100%;
  301. }
  302. </style>