chartBox.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <div :class="['chart-render-box', isPcShow ? 'chart-render-box-pc' : '']">
  3. <div class="label-box">
  4. <div>
  5. <span
  6. class="color-box"
  7. :style="{ background: colorMap.get(keyVal)[0] }"
  8. ></span>
  9. <span>{{ data.labelName }}</span>
  10. </div>
  11. <div>
  12. <span
  13. class="color-box"
  14. :style="{ background: colorMap.get(keyVal)[1] }"
  15. ></span>
  16. <span>增</span>
  17. </div>
  18. <div>
  19. <span
  20. class="color-box"
  21. :style="{ background: colorMap.get(keyVal)[2] }"
  22. ></span>
  23. <span>减</span>
  24. </div>
  25. </div>
  26. <div class="chart-content">
  27. <!-- <img class="mark-img" src="../../../../../assets/hzyb/chart/mark.png" alt=""> -->
  28. <div class="chart-box" :id="'chart-box-' + keyVal"></div>
  29. </div>
  30. <!-- 详情弹窗 -->
  31. <el-dialog
  32. :visible.sync="showDetailDia"
  33. title="详情"
  34. :width="500"
  35. draggable
  36. :close-on-click-modal="false"
  37. append-to-body
  38. custom-class="position-analysis-detail-page-dialog"
  39. >
  40. <div class="detail-pop-wrap">
  41. <h2 class="title">{{ showDetailData.DealShortName }}</h2>
  42. <div class="table-box">
  43. <div class="item">
  44. <div>持{{ showDetailData.TypeName }}</div>
  45. <div>{{ showDetailData.DealValue }}</div>
  46. </div>
  47. <div class="item">
  48. <div>增减</div>
  49. <div>{{ showDetailData.DealChange }}</div>
  50. </div>
  51. <div class="item">
  52. <div>占比</div>
  53. <div>{{ (showDetailData.Rate * 100).toFixed(2) }}%</div>
  54. </div>
  55. <div class="item">
  56. <div>前{{ showDetailData.Rank }}名持净多单</div>
  57. <div>{{ showDetailData.BeforeAllValue }}</div>
  58. </div>
  59. <div class="item">
  60. <div>增减</div>
  61. <div>{{ showDetailData.BeforeAllChange }}</div>
  62. </div>
  63. <div class="item">
  64. <div>占比</div>
  65. <div>{{ (showDetailData.BeforeAllRate * 100).toFixed(2) }}%</div>
  66. </div>
  67. </div>
  68. <div class="close-btn" @click="showDetailDia = false">知道了</div>
  69. </div>
  70. </el-dialog>
  71. </div>
  72. </template>
  73. <script>
  74. import Highcharts from "highcharts";
  75. import HighchartsMore from "highcharts/highcharts-more";
  76. import HighchartszhCN from "@/utils/highcahrts-zh_CN";
  77. HighchartszhCN(Highcharts);
  78. HighchartsMore(Highcharts);
  79. export default {
  80. props: {
  81. keyVal: String,
  82. data: Object,
  83. },
  84. computed: {
  85. //图表默认配置项
  86. chartDefaultOpts() {
  87. let that = this;
  88. const chartDefaultOpts = {
  89. chart: {
  90. type: "column",
  91. inverted: true, //xy轴换位置
  92. marginRight: 85,
  93. },
  94. title: {
  95. text: "",
  96. },
  97. //版权信息
  98. credits: { enabled: false },
  99. plotOptions: {
  100. column: {
  101. pointPadding: 0,
  102. stacking: "normal",
  103. dataLabels: {
  104. enabled: true,
  105. align: "right",
  106. color: "#333",
  107. inside: false,
  108. crop: false,
  109. overflow: true,
  110. x: 80,
  111. formatter: function (e) {
  112. return this.point.options.isLabel;
  113. },
  114. },
  115. events: {
  116. click: function (event) {
  117. const name = event.point.category;
  118. that.showDetail(name);
  119. },
  120. },
  121. },
  122. },
  123. legend: {
  124. enabled: false, //关闭图例
  125. },
  126. tooltip: {
  127. enabled: false,
  128. },
  129. };
  130. return chartDefaultOpts;
  131. },
  132. },
  133. watch: {
  134. data(nval) {
  135. nval.List && this.chartRender();
  136. },
  137. },
  138. data() {
  139. return {
  140. //配色表
  141. colorMap: new Map([
  142. ["BuyList", ["#FFD600", "#F32F2F", "#52D424"]],
  143. ["SoldList", ["#C6DDFF", "#363EFF", "#52D424"]],
  144. ["CleanBuyList", ["#FFD600", "#F32F2F", "#52D424"]],
  145. ["CleanSoldList", ["#C6DDFF", "#363EFF", "#52D424"]],
  146. ]),
  147. isPcShow: true,
  148. //点击柱子显示弹窗
  149. showDetailDia: false,
  150. showDetailData: {},
  151. };
  152. },
  153. methods: {
  154. //绘图
  155. chartRender() {
  156. let options = {};
  157. let categories = [];
  158. let series = [
  159. {
  160. name: "总数",
  161. data: [],
  162. },
  163. {
  164. name: "增长",
  165. data: [],
  166. },
  167. {
  168. name: "减少",
  169. data: [],
  170. },
  171. ];
  172. let totalArr = [],
  173. increaseArr = [],
  174. reduceArr = [];
  175. this.data.List.forEach((item, index) => {
  176. categories.push(item.DealShortName);
  177. // 处理series
  178. if (item.DealChange < 0) {
  179. //减少
  180. totalArr.push({ y: item.DealValue });
  181. increaseArr.push({ y: 0 });
  182. reduceArr.push({
  183. y: -item.DealChange,
  184. isLabel: `${item.DealValue}/${item.DealChange}`,
  185. });
  186. } else {
  187. totalArr.push({ y: item.DealValue - item.DealChange });
  188. reduceArr.push({ y: 0 });
  189. increaseArr.push({
  190. y: item.DealChange,
  191. isLabel: `${item.DealValue}/+${item.DealChange}`,
  192. });
  193. }
  194. });
  195. series[0].data = totalArr;
  196. series[1].data = increaseArr;
  197. series[2].data = reduceArr;
  198. let xAxis = {
  199. categories: categories,
  200. tickWidth: 1,
  201. tickPosition: "outside",
  202. };
  203. let yAxis = {
  204. opposite: true,
  205. gridLineWidth: 1,
  206. gridLineColor: "#E4E4E4",
  207. gridLineDashStyle: "longdash",
  208. endOnTick: false,
  209. showLastLabel: true,
  210. lineWidth: 1,
  211. tickWidth: 1,
  212. tickPosition: "outside",
  213. title: {
  214. text: "",
  215. },
  216. reversedStacks: false,
  217. };
  218. options.colors = this.colorMap.get(this.keyVal);
  219. options.xAxis = xAxis;
  220. options.yAxis = yAxis;
  221. options.series = series;
  222. options = { ...this.chartDefaultOpts, ...options };
  223. // console.log('渲染',options);
  224. Highcharts.chart(`chart-box-${this.keyVal}`, options);
  225. },
  226. showDetail(name) {
  227. let data = {};
  228. this.data.List.forEach((item) => {
  229. if (item.DealShortName === name) {
  230. data = item;
  231. }
  232. });
  233. // 判断是否是在pc中 如果是则通知pc显示弹窗
  234. // console.log(window.innerWidth);
  235. this.showDetailDia = true;
  236. this.showDetailData = {
  237. ...data,
  238. type_name: this.data.name,
  239. };
  240. },
  241. },
  242. mounted() {
  243. this.data.List && this.chartRender();
  244. },
  245. };
  246. </script>
  247. <style lang="scss" scoped>
  248. @import "~@/styles/theme-vars.scss";
  249. * {
  250. box-sizing: border-box;
  251. }
  252. .chart-render-box {
  253. width: 100%;
  254. overflow: hidden;
  255. .label-box {
  256. display: flex;
  257. justify-content: center;
  258. div {
  259. margin-right: 30px;
  260. }
  261. .color-box {
  262. display: inline-block;
  263. width: 22px;
  264. height: 22px;
  265. margin-right: 10px;
  266. border-radius: 4px;
  267. }
  268. }
  269. .chart-content {
  270. width: 100%;
  271. height: 70vh;
  272. position: relative;
  273. .mark-img {
  274. position: absolute;
  275. width: 58%;
  276. left: 50%;
  277. top: 50%;
  278. transform: translate(-50%, -50%);
  279. pointer-events: none;
  280. z-index: 2;
  281. }
  282. .chart-box {
  283. width: 100%;
  284. height: 100%;
  285. }
  286. }
  287. }
  288. .mobile-detail-pop-wrap {
  289. width: 90vw;
  290. .title {
  291. text-align: center;
  292. font-size: 32px;
  293. padding: 30px;
  294. }
  295. .table-box {
  296. display: flex;
  297. flex-wrap: wrap;
  298. .item {
  299. width: 33.33%;
  300. text-align: center;
  301. padding: 30px 20px;
  302. border-right: 1px solid #e5e5e5;
  303. border-bottom: 1px solid #e5e5e5;
  304. div:first-child {
  305. color: #999999;
  306. font-size: 24px;
  307. }
  308. div:last-child {
  309. font-size: 32px;
  310. font-weight: 600;
  311. }
  312. }
  313. }
  314. .close-btn {
  315. text-align: center;
  316. line-height: 96px;
  317. color: #e3b377;
  318. }
  319. }
  320. .detail-pop-wrap {
  321. .title {
  322. text-align: center;
  323. font-size: 16px;
  324. padding-bottom: 10px;
  325. margin-top: 0;
  326. }
  327. .table-box {
  328. display: flex;
  329. flex-wrap: wrap;
  330. .item {
  331. width: 33.33%;
  332. text-align: center;
  333. padding: 30px 20px;
  334. border-right: 1px solid #e5e5e5;
  335. border-bottom: 1px solid #e5e5e5;
  336. div:first-child {
  337. color: #999999;
  338. font-size: 14px;
  339. }
  340. div:last-child {
  341. font-size: 16px;
  342. font-weight: 600;
  343. }
  344. }
  345. .item:nth-child(3n) {
  346. border-right: none;
  347. }
  348. .item:nth-child(n + 4) {
  349. border-bottom: none;
  350. }
  351. }
  352. .close-btn {
  353. text-align: center;
  354. line-height: 40px;
  355. color: #fff;
  356. width: 300px;
  357. height: 40px;
  358. background: $theme-color;
  359. border-radius: 41px;
  360. margin-left: auto;
  361. margin-right: auto;
  362. margin-top: 30px;
  363. margin-bottom: 20px;
  364. cursor: pointer;
  365. }
  366. }
  367. // @media (min-width: 600px){
  368. .chart-render-box-pc {
  369. .label-box {
  370. display: flex;
  371. justify-content: center;
  372. font-size: 14px;
  373. div {
  374. margin-right: 20px;
  375. }
  376. .color-box {
  377. display: inline-block;
  378. width: 14px;
  379. height: 14px;
  380. margin-right: 8px;
  381. border-radius: 4px;
  382. position: relative;
  383. top: 2px;
  384. }
  385. }
  386. .chart-content {
  387. height: 800px;
  388. }
  389. }
  390. // }
  391. </style>