widgetBarlinechart.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <template>
  2. <div :style="styleObj">
  3. <v-chart ref="myVChart" :option="options" autoresize/>
  4. </div>
  5. </template>
  6. <script>
  7. import {targetWidgetLinkageLogic} from "@/views/bigscreenDesigner/designer/linkageLogic";
  8. export default {
  9. name: "WidgetBarlinechart",
  10. components: {},
  11. props: {
  12. value: Object,
  13. ispreview: Boolean,
  14. },
  15. data() {
  16. return {
  17. options: {
  18. color: [],
  19. grid: {},
  20. title: {
  21. text: "",
  22. textStyle: {
  23. color: "#fff",
  24. },
  25. },
  26. tooltip: {
  27. trigger: "item",
  28. formatter: "{a} <br/>{b} : {c}%",
  29. },
  30. legend: {
  31. textStyle: {
  32. color: "#fff",
  33. },
  34. },
  35. xAxis: [
  36. {
  37. type: "category",
  38. data: [],
  39. axisLabel: {
  40. show: false,
  41. textStyle: {
  42. color: "#fff",
  43. },
  44. },
  45. },
  46. ],
  47. yAxis: [
  48. {
  49. type: "value",
  50. name: "",
  51. min: 0,
  52. max: 250,
  53. interval: 50,
  54. axisLabel: {
  55. show: true,
  56. textStyle: {
  57. color: "#fff",
  58. },
  59. },
  60. },
  61. {
  62. type: "value",
  63. name: "",
  64. min: 0,
  65. max: 25,
  66. interval: 5,
  67. axisLabel: {
  68. show: true,
  69. textStyle: {
  70. color: "#fff",
  71. },
  72. },
  73. },
  74. ],
  75. series: [
  76. {
  77. name: "",
  78. type: "bar",
  79. yAxisIndex: 0,
  80. data: [],
  81. itemStyle: {
  82. barBorderRadius: null,
  83. },
  84. },
  85. {
  86. name: "",
  87. type: "line",
  88. yAxisIndex: 1,
  89. data: [],
  90. itemStyle: {},
  91. },
  92. ],
  93. },
  94. optionsStyle: {}, // 样式
  95. optionsData: {}, // 数据
  96. optionsCollapse: {}, // 图标属性
  97. optionsSetup: {},
  98. flagInter: null,
  99. };
  100. },
  101. computed: {
  102. styleObj() {
  103. return {
  104. position: this.ispreview ? "absolute" : "static",
  105. width: this.optionsStyle.width + "px",
  106. height: this.optionsStyle.height + "px",
  107. left: this.optionsStyle.left + "px",
  108. top: this.optionsStyle.top + "px",
  109. background: this.optionsSetup.background,
  110. };
  111. },
  112. allComponentLinkage() {
  113. return this.$store.state.designer.allComponentLinkage;
  114. },
  115. },
  116. watch: {
  117. value: {
  118. handler(val) {
  119. this.optionsStyle = val.position;
  120. this.optionsData = val.data;
  121. this.optionsCollapse = val.collapse;
  122. this.optionsSetup = val.setup;
  123. this.editorOptions();
  124. },
  125. deep: true,
  126. },
  127. },
  128. created() {
  129. this.optionsStyle = this.value.position;
  130. this.optionsData = this.value.data;
  131. this.optionsCollapse = this.value.collapse;
  132. this.optionsSetup = this.value.setup;
  133. this.editorOptions();
  134. targetWidgetLinkageLogic(this); // 联动-目标组件逻辑
  135. },
  136. methods: {
  137. // 修改图标options属性
  138. editorOptions() {
  139. this.setOptionsTitle();
  140. this.setOptionsX();
  141. this.setOptionsY();
  142. this.setOptionsLine();
  143. this.setOptionsBar();
  144. this.setOptionsTooltip();
  145. this.setOptionsData();
  146. this.setOptionsMargin();
  147. this.setOptionsLegend();
  148. this.setOptionsColor();
  149. },
  150. // 标题修改
  151. setOptionsTitle() {
  152. const optionsSetup = this.optionsSetup;
  153. const title = {
  154. text: optionsSetup.text,
  155. show: optionsSetup.isShowTitle,
  156. left: optionsSetup.titleLeft,
  157. top: optionsSetup.titleTop + "%",
  158. itemGap: optionsSetup.titleItemGap,
  159. textStyle: {
  160. color: optionsSetup.textColor,
  161. fontSize: optionsSetup.textFontSize,
  162. fontWeight: optionsSetup.textFontWeight,
  163. fontStyle: optionsSetup.textFontStyle,
  164. fontFamily: optionsSetup.textFontFamily,
  165. },
  166. subtext: optionsSetup.subtext,
  167. subtextStyle: {
  168. color: optionsSetup.subtextColor,
  169. fontWeight: optionsSetup.subtextFontWeight,
  170. fontSize: optionsSetup.subtextFontSize,
  171. fontStyle: optionsSetup.subtextFontStyle,
  172. fontFamily: optionsSetup.subtextFontFamily
  173. },
  174. };
  175. this.options.title = title;
  176. },
  177. // X轴设置
  178. setOptionsX() {
  179. const optionsSetup = this.optionsSetup;
  180. const xAxis = {
  181. type: "category",
  182. // 坐标轴是否显示
  183. show: optionsSetup.isShowX,
  184. max: optionsSetup.maxX !== "" ? optionsSetup.maxX : null,
  185. min: optionsSetup.minX !== "" ? optionsSetup.minX : null,
  186. position: optionsSetup.positionX,
  187. offset: optionsSetup.offsetX,
  188. // 坐标轴名称
  189. name: optionsSetup.nameX,
  190. nameLocation: optionsSetup.nameLocationX,
  191. nameTextStyle: {
  192. color: optionsSetup.nameColorX,
  193. fontSize: optionsSetup.nameFontSizeX,
  194. fontWeight: optionsSetup.nameFontWeightX,
  195. fontStyle: optionsSetup.nameFontStyleX,
  196. fontFamily: optionsSetup.nameFontFamilyX,
  197. },
  198. // 轴反转
  199. inverse: optionsSetup.reversalX,
  200. axisLabel: {
  201. show: optionsSetup.isShowAxisLabelX,
  202. interval: optionsSetup.textIntervalX,
  203. // 文字角度
  204. rotate: optionsSetup.textAngleX,
  205. textStyle: {
  206. // 坐标文字颜色
  207. color: optionsSetup.textColorX,
  208. fontSize: optionsSetup.textFontSizeX,
  209. fontWeight: optionsSetup.textFontWeightX,
  210. fontStyle: optionsSetup.textFontStyleX,
  211. fontFamily: optionsSetup.textFontFamilyX,
  212. },
  213. },
  214. // X轴线
  215. axisLine: {
  216. show: optionsSetup.isShowAxisLineX,
  217. lineStyle: {
  218. color: optionsSetup.lineColorX,
  219. width: optionsSetup.lineWidthX,
  220. },
  221. },
  222. // X轴刻度线
  223. axisTick: {
  224. show: optionsSetup.isShowAxisLineX,
  225. lineStyle: {
  226. color: optionsSetup.lineColorX,
  227. width: optionsSetup.lineWidthX,
  228. },
  229. },
  230. // X轴分割线
  231. splitLine: {
  232. show: optionsSetup.isShowSplitLineX,
  233. lineStyle: {
  234. color: optionsSetup.splitLineColorX,
  235. width: optionsSetup.splitLineWidthX,
  236. },
  237. },
  238. };
  239. this.options.xAxis = xAxis;
  240. },
  241. // Y轴设置
  242. setOptionsY() {
  243. const optionsSetup = this.optionsSetup;
  244. const yAxis = [
  245. {
  246. max: optionsSetup.maxYLeft !== "" ? optionsSetup.maxYLeft : null,
  247. min: optionsSetup.minYLeft !== "" ? optionsSetup.minYLeft : null,
  248. type: "value",
  249. scale: optionsSetup.scaleYLeft,
  250. // 均分
  251. splitNumber: optionsSetup.splitNumberYLeft,
  252. // 坐标轴是否显示
  253. show: optionsSetup.isShowYLeft,
  254. position: optionsSetup.positionYLeft,
  255. offset: optionsSetup.offsetYLeft,
  256. // 坐标轴名称
  257. name: optionsSetup.textNameYLeft,
  258. nameLocation: optionsSetup.nameLocationYLeft,
  259. // 别名
  260. nameTextStyle: {
  261. color: optionsSetup.nameColorYLeft,
  262. fontSize: optionsSetup.nameFontSizeYLeft,
  263. fontWeight: optionsSetup.nameFontWeightYLeft,
  264. fontStyle: optionsSetup.nameFontStyleYLeft,
  265. fontFamily: optionsSetup.nameFontFamilyYLeft,
  266. },
  267. axisLabel: {
  268. show: optionsSetup.isShowAxisLabelYLeft,
  269. // 文字角度
  270. rotate: optionsSetup.textAngleYLeft,
  271. textStyle: {
  272. // 坐标文字颜色
  273. color: optionsSetup.textColorYLeft,
  274. fontSize: optionsSetup.textFontSizeYLeft,
  275. fontWeight: optionsSetup.textFontWeightYLeft,
  276. fontStyle: optionsSetup.textFontStyleYLeft,
  277. fontFamily: optionsSetup.textFontFamilyYLeft,
  278. },
  279. },
  280. axisLine: {
  281. show: optionsSetup.isShowAxisLineYLeft,
  282. lineStyle: {
  283. width: optionsSetup.lineWidthYLeft,
  284. color: optionsSetup.lineColorYLeft,
  285. },
  286. },
  287. axisTick: {
  288. // 刻度
  289. show: optionsSetup.isShowAxisLineYLeft,
  290. lineStyle: {
  291. width: optionsSetup.lineWidthYLeft,
  292. color: optionsSetup.lineColorYLeft,
  293. },
  294. },
  295. splitLine: {
  296. show: optionsSetup.isShowSplitLineYLeft,
  297. lineStyle: {
  298. color: optionsSetup.splitLineColorYLeft,
  299. width: optionsSetup.splitLineFontWidthYLeft,
  300. },
  301. },
  302. },
  303. {
  304. max: optionsSetup.maxYRight !== "" ? optionsSetup.maxYRight : null,
  305. type: "value",
  306. scale: optionsSetup.scaleYRight,
  307. // 均分
  308. splitNumber: optionsSetup.splitNumberYRight,
  309. // 坐标轴是否显示
  310. show: optionsSetup.isShowYRight,
  311. position: optionsSetup.positionYRight,
  312. offset: optionsSetup.offsetYRight,
  313. // 坐标轴名称
  314. name: optionsSetup.textNameYRight,
  315. nameLocation: optionsSetup.nameLocationYRight,
  316. // 别名
  317. nameTextStyle: {
  318. color: optionsSetup.nameColorYRight,
  319. fontSize: optionsSetup.nameFontSizeYRight,
  320. fontWeight: optionsSetup.nameFontWeightYRight,
  321. fontStyle: optionsSetup.nameFontStyleYRight,
  322. fontFamily: optionsSetup.nameFontFamilyYRight,
  323. },
  324. axisLabel: {
  325. show: optionsSetup.isShowAxisLabelYRight,
  326. // 文字角度
  327. rotate: optionsSetup.textAngleYRight,
  328. textStyle: {
  329. // 坐标文字颜色
  330. color: optionsSetup.textColorYRight,
  331. fontSize: optionsSetup.textFontSizeYRight,
  332. fontWeight: optionsSetup.textFontWeightYRight,
  333. fontStyle: optionsSetup.textFontStyleYRight,
  334. fontFamily: optionsSetup.textFontFamilyYRight,
  335. },
  336. },
  337. axisLine: {
  338. show: optionsSetup.isShowAxisLineYRight,
  339. lineStyle: {
  340. width: optionsSetup.lineWidthYRight,
  341. color: optionsSetup.lineColorYRight,
  342. },
  343. },
  344. axisTick: {
  345. // 刻度
  346. show: optionsSetup.isShowAxisLineYRight,
  347. lineStyle: {
  348. width: optionsSetup.lineWidthYRight,
  349. color: optionsSetup.lineColorYRight,
  350. }
  351. },
  352. splitLine: {
  353. show: optionsSetup.isShowSplitLineYRight,
  354. lineStyle: {
  355. color: optionsSetup.splitLineColorYRight,
  356. width: optionsSetup.splitLineFontWidthYRight,
  357. },
  358. },
  359. },
  360. ];
  361. this.options.yAxis = yAxis;
  362. },
  363. // 折线设置 数值设置
  364. setOptionsLine() {
  365. const optionsSetup = this.optionsSetup;
  366. const series = this.options.series;
  367. for (const key in series) {
  368. if (series[key].type === "line") {
  369. series[key].symbol = optionsSetup.symbol;
  370. series[key].showSymbol = optionsSetup.markPoint;
  371. series[key].symbolSize = optionsSetup.pointSize;
  372. series[key].smooth = optionsSetup.smoothCurve;
  373. if (optionsSetup.area) {
  374. series[key].areaStyle = {
  375. opacity: optionsSetup.areaThickness / 100,
  376. };
  377. } else {
  378. series[key].areaStyle = {
  379. opacity: 0,
  380. };
  381. }
  382. series[key].lineStyle = {
  383. width: optionsSetup.lineWidth,
  384. };
  385. series[key].itemStyle.borderRadius = optionsSetup.radius;
  386. series[key].label = {
  387. show: optionsSetup.isShowLine,
  388. position: optionsSetup.fontPositionLine,
  389. distance: optionsSetup.fontDistanceLine,
  390. fontSize: optionsSetup.fontSizeLine,
  391. color: optionsSetup.fontColorLine,
  392. fontWeight: optionsSetup.fontWeightLine,
  393. formatter: !!optionsSetup.percentSignLine ? '{c}%' : '{c}',
  394. fontStyle: optionsSetup.fontStyleLine,
  395. fontFamily: optionsSetup.fontFamilyLine,
  396. };
  397. }
  398. }
  399. this.options.series = series;
  400. },
  401. // 柱体设置 数值设置
  402. setOptionsBar() {
  403. const optionsSetup = this.optionsSetup;
  404. const series = this.options.series;
  405. for (const key in series) {
  406. if (series[key].type === "bar") {
  407. series[key].label = {
  408. show: optionsSetup.isShowBar,
  409. position: optionsSetup.fontPositionBar,
  410. distance: optionsSetup.fontDistanceBar,
  411. fontSize: optionsSetup.fontSizeBar,
  412. color: optionsSetup.fontColorBar,
  413. fontWeight: optionsSetup.fontWeightBar,
  414. formatter: !!optionsSetup.percentSignBar ? '{c}%' : '{c}',
  415. fontStyle: optionsSetup.fontStyleBar,
  416. fontFamily: optionsSetup.fontFamilyBar,
  417. };
  418. //柱体背景属性
  419. series[key].showBackground = optionsSetup.isShowBackground;
  420. series[key].backgroundStyle = {
  421. color: optionsSetup.backgroundStyleColor,
  422. borderColor: optionsSetup.backgroundStyleBorderColor,
  423. borderWidth: optionsSetup.backgroundStyleBorderWidth,
  424. borderType: optionsSetup.backgroundStyleBorderType,
  425. shadowBlur: optionsSetup.backgroundStyleShadowBlur,
  426. shadowColor: optionsSetup.backgroundStyleShadowColor,
  427. opacity: optionsSetup.backgroundStyleOpacity / 100,
  428. };
  429. series[key].barWidth = optionsSetup.maxWidth;
  430. series[key].barMinHeight = optionsSetup.minHeight;
  431. series[key].itemStyle.barBorderRadius = optionsSetup.radius;
  432. }
  433. }
  434. this.options.series = series;
  435. },
  436. // tooltip 设置
  437. setOptionsTooltip() {
  438. const optionsSetup = this.optionsSetup;
  439. const tooltip = {
  440. show: optionsSetup.isShowTooltip,
  441. trigger: optionsSetup.tooltipTrigger,
  442. axisPointer: {
  443. type: optionsSetup.tooltipAxisPointerType,
  444. },
  445. backgroundColor: optionsSetup.tooltipBackgroundColor,
  446. borderColor: optionsSetup.tooltipBorderColor,
  447. borderWidth: optionsSetup.tooltipBorderWidth,
  448. textStyle: {
  449. color: optionsSetup.tooltipColor,
  450. fontSize: optionsSetup.tooltipFontSize,
  451. fontWeight: optionsSetup.tooltipFontWeight,
  452. fontStyle: optionsSetup.tooltipFontStyle,
  453. fontFamily: optionsSetup.tooltipFontFamily,
  454. },
  455. };
  456. this.options.tooltip = tooltip;
  457. },
  458. // 边距设置
  459. setOptionsMargin() {
  460. const optionsSetup = this.optionsSetup;
  461. const grid = {
  462. left: optionsSetup.marginLeft,
  463. right: optionsSetup.marginRight,
  464. bottom: optionsSetup.marginBottom,
  465. top: optionsSetup.marginTop,
  466. containLabel: true,
  467. };
  468. this.options.grid = grid;
  469. },
  470. setOptionsLegend() {
  471. const optionsSetup = this.optionsSetup;
  472. const legend = {
  473. show: optionsSetup.isShowLegend,
  474. left: optionsSetup.lateralPosition,
  475. //right: optionsSetup.lateralPosition,
  476. top: optionsSetup.longitudinalPosition,
  477. //bottom: optionsSetup.longitudinalPosition,
  478. orient: optionsSetup.layoutFront,
  479. textStyle: {
  480. color: optionsSetup.legendColor,
  481. fontSize: optionsSetup.legendFontSize,
  482. fontWeight: optionsSetup.legendFontWeight,
  483. fontStyle: optionsSetup.legendFontStyle,
  484. fontFamily: optionsSetup.legendFontFamily,
  485. },
  486. itemHeight: optionsSetup.legendHeight,
  487. itemWidth: optionsSetup.legendWidth,
  488. };
  489. this.options.legend = legend;
  490. },
  491. // 图例名称设置
  492. setOptionsLegendName(name) {
  493. const optionsSetup = this.optionsSetup;
  494. const series = this.options.series;
  495. const legendName = optionsSetup.legendName;
  496. // 图例没有手动写则显示原值,写了则显示新值
  497. if (null == legendName || legendName === "") {
  498. for (let i = 0; i < name.length; i++) {
  499. series[i].name = name[i];
  500. }
  501. this.options.legend["data"] = name;
  502. } else {
  503. const arr = legendName.split("|");
  504. for (let i = 0; i < arr.length; i++) {
  505. series[i].name = arr[i];
  506. }
  507. this.options.legend["data"] = arr;
  508. }
  509. },
  510. // 图例颜色修改
  511. setOptionsColor() {
  512. const optionsSetup = this.optionsSetup;
  513. const customColor = optionsSetup.customColor;
  514. if (!customColor) return;
  515. const arrColor = [];
  516. for (let i = 0; i < customColor.length; i++) {
  517. arrColor.push(customColor[i].color);
  518. }
  519. this.options.color = arrColor;
  520. this.options = Object.assign({}, this.options);
  521. },
  522. // 数据处理
  523. setOptionsData(e, paramsConfig) {
  524. const optionsData = this.optionsData; // 数据类型 静态 or 动态
  525. // 联动接收者逻辑开始
  526. optionsData.dynamicData = optionsData.dynamicData || {}; // 兼容 dynamicData undefined
  527. const myDynamicData = optionsData.dynamicData;
  528. clearInterval(this.flagInter); // 不管咋,先干掉上一次的定时任务,避免多跑
  529. if (
  530. e &&
  531. optionsData.dataType !== "staticData" &&
  532. Object.keys(myDynamicData.contextData).length
  533. ) {
  534. const keyArr = Object.keys(myDynamicData.contextData);
  535. paramsConfig.forEach((conf) => {
  536. if (keyArr.includes(conf.targetKey)) {
  537. myDynamicData.contextData[conf.targetKey] = e[conf.originKey];
  538. }
  539. });
  540. }
  541. // 联动接收者逻辑结束
  542. optionsData.dataType === "staticData"
  543. ? this.staticDataFn(optionsData.staticData)
  544. : this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
  545. },
  546. staticDataFn(val) {
  547. const series = this.options.series;
  548. let axis = [];
  549. let bar = [];
  550. let line = [];
  551. for (const i in val) {
  552. axis[i] = val[i].axis;
  553. bar[i] = val[i].bar;
  554. line[i] = val[i].line;
  555. }
  556. // x轴
  557. this.options.xAxis.data = axis;
  558. // series
  559. for (const i in series) {
  560. if (series[i].type === "bar") {
  561. series[i].data = bar;
  562. } else {
  563. series[i].data = line;
  564. }
  565. }
  566. const legendName = [];
  567. legendName.push("bar");
  568. legendName.push("line");
  569. const optionsSetup = this.optionsSetup;
  570. // 根据图表的宽度 x轴的字体大小、长度来估算X轴的label能展示多少个字
  571. const rowsNum = optionsSetup.textRowsNum !== "" ? optionsSetup.textRowsNum : parseInt((this.optionsStyle.width / axis.length) / optionsSetup.textFontSizeX);
  572. const axisLabel = {
  573. show: optionsSetup.isShowAxisLabelX,
  574. interval: optionsSetup.textIntervalX,
  575. // 文字角度
  576. rotate: optionsSetup.textAngleX,
  577. textStyle: {
  578. // 坐标文字颜色
  579. color: optionsSetup.textColorX,
  580. fontSize: optionsSetup.textFontSizeX,
  581. fontWeight: optionsSetup.textFontWeightX,
  582. fontStyle: optionsSetup.textFontStyleX,
  583. fontFamily: optionsSetup.textFontFamilyX,
  584. },
  585. // 自动换行
  586. formatter: function (value, index) {
  587. const strs = value.split('');
  588. let str = ''
  589. for (let i = 0, s; s = strs[i++];) {
  590. str += s;
  591. if (!(i % rowsNum)) str += '\n';
  592. }
  593. return str
  594. }
  595. }
  596. if (optionsSetup.textRowsBreakAuto) {
  597. this.options.xAxis.axisLabel = axisLabel;
  598. }
  599. this.options.legend["data"] = legendName;
  600. this.setOptionsLegendName(legendName);
  601. },
  602. dynamicDataFn(val, refreshTime) {
  603. if (!val) return;
  604. if (this.ispreview) {
  605. this.getEchartData(val);
  606. this.flagInter = setInterval(() => {
  607. this.getEchartData(val);
  608. }, refreshTime);
  609. } else {
  610. this.getEchartData(val);
  611. }
  612. },
  613. getEchartData(val) {
  614. const data = this.queryEchartsData(val);
  615. data.then((res) => {
  616. this.renderingFn(res);
  617. });
  618. },
  619. renderingFn(val) {
  620. this.options.xAxis.data = val.xAxis;
  621. // series
  622. const series = this.options.series;
  623. const legendName = [];
  624. for (const i in series) {
  625. for (const j in val.series) {
  626. if (series[i].type === val.series[j].type) {
  627. series[i].data = val.series[j].data;
  628. legendName.push(val.series[j].name);
  629. }
  630. }
  631. }
  632. const optionsSetup = this.optionsSetup;
  633. // 根据图表的宽度 x轴的字体大小、长度来估算X轴的label能展示多少个字
  634. const xAxisDataLength = val.length !== 0 ? val.xAxis.length : 1;
  635. const rowsNum = optionsSetup.textRowsNum !== "" ? optionsSetup.textRowsNum : parseInt((this.optionsStyle.width / xAxisDataLength) / optionsSetup.textFontSizeX);
  636. const axisLabel = {
  637. show: optionsSetup.isShowAxisLabelX,
  638. interval: optionsSetup.textIntervalX,
  639. // 文字角度
  640. rotate: optionsSetup.textAngleX,
  641. textStyle: {
  642. // 坐标文字颜色
  643. color: optionsSetup.textColorX,
  644. fontSize: optionsSetup.textFontSizeX,
  645. fontWeight: optionsSetup.textFontWeightX,
  646. fontStyle: optionsSetup.textFontStyleX,
  647. fontFamily: optionsSetup.textFontFamilyX,
  648. },
  649. // 自动换行
  650. formatter: function (value, index) {
  651. const strs = value.split('');
  652. let str = ''
  653. for (let i = 0, s; s = strs[i++];) {
  654. str += s;
  655. if (!(i % rowsNum)) str += '\n';
  656. }
  657. return str
  658. }
  659. }
  660. if (optionsSetup.textRowsBreakAuto) {
  661. this.options.xAxis.axisLabel = axisLabel;
  662. }
  663. this.options.legend["data"] = legendName;
  664. this.setOptionsLegendName(legendName);
  665. },
  666. },
  667. };
  668. </script>
  669. <style scoped lang="scss">
  670. .echarts {
  671. width: 100%;
  672. height: 100%;
  673. overflow: hidden;
  674. }
  675. </style>