index11.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div>
  3. <div style="width:800px">
  4. <x-chart ref="child" id="highcharts" class="high" :option="option"></x-chart>
  5. </div>
  6. <div class="control">
  7. <div ref="box" style="width:50%;border:1px solid lightgrey;float:left">
  8. <div>
  9. <span class="text">Curve Display:</span>
  10. <el-select
  11. size="mini"
  12. multiple
  13. collapse-tags
  14. style="margin-top:10px"
  15. v-model="CurveValue"
  16. placeholder="请选择显示项"
  17. @change="showCurve"
  18. >
  19. <el-option :label="'All'" :value="'All'"></el-option>
  20. <el-option
  21. v-for="(item,index) in option.series "
  22. :key="index"
  23. :label="item.name"
  24. :value="item.name"
  25. ></el-option>
  26. </el-select>
  27. </div>
  28. <br />
  29. <div>
  30. <span class="text">Line Width:</span>
  31. <el-select
  32. size="mini"
  33. style="margin-left:15px"
  34. v-model="linevalue"
  35. placeholder="请选择线宽"
  36. @change="changeLine"
  37. >
  38. <el-option
  39. v-for="item in lineWdith "
  40. :key="item.value"
  41. :label="item.label"
  42. :value="item.value"
  43. ></el-option>
  44. </el-select>
  45. </div>
  46. <div>
  47. <span class="text">BackGroundColor:</span>
  48. <el-color-picker
  49. size="mini"
  50. style="margin-top:10px"
  51. v-model="back_color"
  52. @change="changeBackColor"
  53. ></el-color-picker>
  54. </div>
  55. </div>
  56. <div style="width:50%;border:1px solid lightgrey;float:right">
  57. <div>
  58. <span class="text">Curve Display:</span>
  59. <el-select size="mini" v-model="displayLine" style="margin-top:10px" placeholder="请选择隐藏项">
  60. <el-option
  61. v-for="(item,index) in option.series "
  62. :key="index"
  63. :label="item.name"
  64. :value="item.name"
  65. :disabled="item.display"
  66. ></el-option>
  67. </el-select>
  68. </div>
  69. <br />
  70. <div>
  71. <span class="text">Line Type:</span>
  72. <el-select size="mini" v-model="lineType" style="margin-left:15px" placeholder="请选择线的类型">
  73. <el-option
  74. v-for="item in lineStyle "
  75. :key="item.value"
  76. :label="item.label"
  77. :value="item.value"
  78. ></el-option>
  79. </el-select>
  80. </div>
  81. <div>
  82. <span class="text">Line Color:</span>
  83. <el-color-picker
  84. size="mini"
  85. v-model="lineColor"
  86. style="margin-top:10px"
  87. @change="changeLineColor"
  88. ></el-color-picker>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. </template>
  94. <script>
  95. // 导入chart组件
  96. import XChart from "@/components/chart";
  97. import dataJson from "@/assets/data.json";
  98. export default {
  99. data() {
  100. return {
  101. lineWdith: [
  102. {
  103. value: "1",
  104. label: "1",
  105. },
  106. {
  107. value: "2",
  108. label: "2",
  109. },
  110. {
  111. value: "3",
  112. label: "3",
  113. },
  114. {
  115. value: "4",
  116. label: "4",
  117. },
  118. ],
  119. lineStyle: [
  120. {
  121. value: "Line",
  122. label: "Line",
  123. },
  124. {
  125. value: "point",
  126. label: "point",
  127. },
  128. {
  129. value: "Square",
  130. label: "Square",
  131. },
  132. {
  133. value: "Triangle",
  134. label: "Triangle",
  135. },
  136. ],
  137. displayLine: "",
  138. back_color: "#778899",
  139. lineType: "",
  140. lineColor: "",
  141. linevalue: "1",
  142. CurveValue: ["All"],
  143. newOption: [],
  144. option: {
  145. title: {
  146. text: dataJson.title,
  147. },
  148. chart: {
  149. plotBackgroundColor: "#778899",
  150. borderWidth: 1,
  151. },
  152. subtitle: {
  153. text: "数据来源:converge",
  154. },
  155. yAxis: {
  156. title: {
  157. text: "值得大小",
  158. },
  159. },
  160. xAxis: {},
  161. plotOptions: {
  162. series: {
  163. lineWidth: 1,
  164. label: {
  165. connectorAllowed: false,
  166. },
  167. marker: {
  168. radius: 5,
  169. },
  170. pointStart: 1,
  171. },
  172. },
  173. series: [],
  174. credits: {
  175. enabled: false,
  176. },
  177. responsive: {
  178. rules: [
  179. {
  180. condition: {
  181. maxWidth: 500,
  182. },
  183. chartOptions: {
  184. legend: {
  185. layout: "horizontal",
  186. align: "center",
  187. verticalAlign: "bottom",
  188. },
  189. },
  190. },
  191. ],
  192. },
  193. },
  194. };
  195. },
  196. created() {
  197. var jsonStr = dataJson;
  198. for (var i in jsonStr.VARIABLES) {
  199. var obj = {
  200. name: "",
  201. data: [],
  202. color: "",
  203. display: true,
  204. };
  205. obj.name = jsonStr.VARIABLES[i];
  206. this.option.series.push(obj);
  207. }
  208. for (var i in jsonStr.VARIABLES) {
  209. for (var j in jsonStr.value) {
  210. this.option.series[i].data.push(
  211. Number(jsonStr.value[j][i].toFixed(10))
  212. );
  213. }
  214. }
  215. let oldoption = this.option;
  216. this.newOption = { ...oldoption };
  217. },
  218. watch: {
  219. "option.plotOptions.series.lineWidth": {
  220. handler(oleVal, newVal) {
  221. },
  222. deep: true,
  223. immediate: true,
  224. },
  225. },
  226. methods: {
  227. showCurve() {
  228. console.log(this.option.series);
  229. var nameArr = [];
  230. let val = this.CurveValue;
  231. for (var i in val) {
  232. if (val[i] == "All") {
  233. this.CurveValue = ["All"];
  234. this.newOption.series = this.option.series;
  235. this.$refs.child.showChart("highcharts", this.newOption);
  236. return;
  237. } else {
  238. var arr = this.option.series.filter((ele) => {
  239. return ele.name == val[i];
  240. });
  241. nameArr.push(arr[0]);
  242. }
  243. }
  244. this.changeDisplay();
  245. this.newOption.series = nameArr;
  246. this.$refs.child.showChart("highcharts", this.newOption);
  247. },
  248. changeDisplay() {
  249. let val = this.CurveValue;
  250. for (var i in val) {
  251. for (var j in this.option.series)
  252. if (val[i] == this.option.series[j].name) {
  253. this.option.series[j].display = false;
  254. }
  255. }
  256. },
  257. changeBackColor() {
  258. let val = this.back_color;
  259. this.$set(this.newOption.chart, "plotBackgroundColor", val);
  260. this.$refs.child.showChart("highcharts", this.newOption);
  261. },
  262. changeLine() {
  263. let val = this.linevalue;
  264. this.$set(this.option.plotOptions.series, "lineWidth", Number(val));
  265. // console.log(this.option.plotOptions.series.lineWidth);
  266. this.$refs.child.showChart("highcharts", this.newOption);
  267. },
  268. changeLineColor() {
  269. let val = this.lineColor;
  270. let lineVal = this.displayLine;
  271. if (lineVal == "") {
  272. this.$message.error("请先选择线条");
  273. return;
  274. }
  275. for (var i in this.newOption.series) {
  276. if (this.newOption.series[i].name == lineVal) {
  277. this.newOption.series[i].color = val;
  278. }
  279. }
  280. this.$refs.child.showChart("highcharts", this.newOption);
  281. },
  282. },
  283. components: {
  284. XChart,
  285. },
  286. };
  287. </script>
  288. <style>
  289. .chart {
  290. width: 200px;
  291. height: 100px;
  292. }
  293. .control {
  294. position: relative;
  295. width: 800px;
  296. height: 200px;
  297. border: 1px solid burlywood;
  298. }
  299. .text {
  300. font-size: 12px;
  301. margin-left: 10px;
  302. }
  303. </style>