widgetBarlinechart.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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. position: optionsSetup.positionX,
  185. offset: optionsSetup.offsetX,
  186. // 坐标轴名称
  187. name: optionsSetup.nameX,
  188. nameLocation: optionsSetup.nameLocationX,
  189. nameTextStyle: {
  190. color: optionsSetup.nameColorX,
  191. fontSize: optionsSetup.nameFontSizeX,
  192. fontWeight: optionsSetup.nameFontWeightX,
  193. fontStyle: optionsSetup.nameFontStyleX,
  194. fontFamily: optionsSetup.nameFontFamilyX,
  195. },
  196. // 轴反转
  197. inverse: optionsSetup.reversalX,
  198. axisLabel: {
  199. show: optionsSetup.isShowAxisLabelX,
  200. interval: optionsSetup.textIntervalX,
  201. // 文字角度
  202. rotate: optionsSetup.textAngleX,
  203. textStyle: {
  204. // 坐标文字颜色
  205. color: optionsSetup.textColorX,
  206. fontSize: optionsSetup.textFontSizeX,
  207. fontWeight: optionsSetup.textFontWeightX,
  208. fontStyle: optionsSetup.textFontStyleX,
  209. fontFamily: optionsSetup.textFontFamilyX,
  210. },
  211. },
  212. // X轴线
  213. axisLine: {
  214. show: optionsSetup.isShowAxisLineX,
  215. lineStyle: {
  216. color: optionsSetup.lineColorX,
  217. width: optionsSetup.lineWidthX,
  218. },
  219. },
  220. // X轴刻度线
  221. axisTick: {
  222. show: optionsSetup.isShowAxisLineX,
  223. lineStyle: {
  224. color: optionsSetup.lineColorX,
  225. width: optionsSetup.lineWidthX,
  226. },
  227. },
  228. // X轴分割线
  229. splitLine: {
  230. show: optionsSetup.isShowSplitLineX,
  231. lineStyle: {
  232. color: optionsSetup.splitLineColorX,
  233. width: optionsSetup.splitLineWidthX,
  234. },
  235. },
  236. };
  237. this.options.xAxis = xAxis;
  238. },
  239. // Y轴设置
  240. setOptionsY() {
  241. const optionsSetup = this.optionsSetup;
  242. const yAxis = [
  243. {
  244. max: optionsSetup.maxYLeft !== "" ? optionsSetup.maxYLeft : null,
  245. min: optionsSetup.minYLeft !== "" ? optionsSetup.minYLeft : null,
  246. type: "value",
  247. scale: optionsSetup.scaleYLeft,
  248. // 均分
  249. splitNumber: optionsSetup.splitNumberYLeft,
  250. // 坐标轴是否显示
  251. show: optionsSetup.isShowYLeft,
  252. position: optionsSetup.positionYLeft,
  253. offset: optionsSetup.offsetYLeft,
  254. // 坐标轴名称
  255. name: optionsSetup.textNameYLeft,
  256. nameLocation: optionsSetup.nameLocationYLeft,
  257. // 别名
  258. nameTextStyle: {
  259. color: optionsSetup.nameColorYLeft,
  260. fontSize: optionsSetup.nameFontSizeYLeft,
  261. fontWeight: optionsSetup.nameFontWeightYLeft,
  262. fontStyle: optionsSetup.nameFontStyleYLeft,
  263. fontFamily: optionsSetup.nameFontFamilyYLeft,
  264. },
  265. axisLabel: {
  266. show: optionsSetup.isShowAxisLabelYLeft,
  267. // 文字角度
  268. rotate: optionsSetup.textAngleYLeft,
  269. textStyle: {
  270. // 坐标文字颜色
  271. color: optionsSetup.textColorYLeft,
  272. fontSize: optionsSetup.textFontSizeYLeft,
  273. fontWeight: optionsSetup.textFontWeightYLeft,
  274. fontStyle: optionsSetup.textFontStyleYLeft,
  275. fontFamily: optionsSetup.textFontFamilyYLeft,
  276. },
  277. },
  278. axisLine: {
  279. show: optionsSetup.isShowAxisLineYLeft,
  280. lineStyle: {
  281. width: optionsSetup.lineWidthYLeft,
  282. color: optionsSetup.lineColorYLeft,
  283. },
  284. },
  285. axisTick: {
  286. // 刻度
  287. show: optionsSetup.isShowAxisLineYLeft,
  288. lineStyle: {
  289. width: optionsSetup.lineWidthYLeft,
  290. color: optionsSetup.lineColorYLeft,
  291. },
  292. },
  293. splitLine: {
  294. show: optionsSetup.isShowSplitLineYLeft,
  295. lineStyle: {
  296. color: optionsSetup.splitLineColorYLeft,
  297. width: optionsSetup.splitLineFontWidthYLeft,
  298. },
  299. },
  300. },
  301. {
  302. max: optionsSetup.maxYRight !== "" ? optionsSetup.maxYRight : null,
  303. type: "value",
  304. scale: optionsSetup.scaleYRight,
  305. // 均分
  306. splitNumber: optionsSetup.splitNumberYRight,
  307. // 坐标轴是否显示
  308. show: optionsSetup.isShowYRight,
  309. position: optionsSetup.positionYRight,
  310. offset: optionsSetup.offsetYRight,
  311. // 坐标轴名称
  312. name: optionsSetup.textNameYRight,
  313. nameLocation: optionsSetup.nameLocationYRight,
  314. // 别名
  315. nameTextStyle: {
  316. color: optionsSetup.nameColorYRight,
  317. fontSize: optionsSetup.nameFontSizeYRight,
  318. fontWeight: optionsSetup.nameFontWeightYRight,
  319. fontStyle: optionsSetup.nameFontStyleYRight,
  320. fontFamily: optionsSetup.nameFontFamilyYRight,
  321. },
  322. axisLabel: {
  323. show: optionsSetup.isShowAxisLabelYRight,
  324. // 文字角度
  325. rotate: optionsSetup.textAngleYRight,
  326. textStyle: {
  327. // 坐标文字颜色
  328. color: optionsSetup.textColorYRight,
  329. fontSize: optionsSetup.textFontSizeYRight,
  330. fontWeight: optionsSetup.textFontWeightYRight,
  331. fontStyle: optionsSetup.textFontStyleYRight,
  332. fontFamily: optionsSetup.textFontFamilyYRight,
  333. },
  334. },
  335. axisLine: {
  336. show: optionsSetup.isShowAxisLineYRight,
  337. lineStyle: {
  338. width: optionsSetup.lineWidthYRight,
  339. color: optionsSetup.lineColorYRight,
  340. },
  341. },
  342. axisTick: {
  343. // 刻度
  344. show: optionsSetup.isShowAxisLineYRight,
  345. lineStyle: {
  346. width: optionsSetup.lineWidthYRight,
  347. color: optionsSetup.lineColorYRight,
  348. }
  349. },
  350. splitLine: {
  351. show: optionsSetup.isShowSplitLineYRight,
  352. lineStyle: {
  353. color: optionsSetup.splitLineColorYRight,
  354. width: optionsSetup.splitLineFontWidthYRight,
  355. },
  356. },
  357. },
  358. ];
  359. this.options.yAxis = yAxis;
  360. },
  361. // 折线设置 数值设置
  362. setOptionsLine() {
  363. const optionsSetup = this.optionsSetup;
  364. const series = this.options.series;
  365. for (const key in series) {
  366. if (series[key].type === "line") {
  367. series[key].symbol = optionsSetup.symbol;
  368. series[key].showSymbol = optionsSetup.markPoint;
  369. series[key].symbolSize = optionsSetup.pointSize;
  370. series[key].smooth = optionsSetup.smoothCurve;
  371. if (optionsSetup.area) {
  372. series[key].areaStyle = {
  373. opacity: optionsSetup.areaThickness / 100,
  374. };
  375. } else {
  376. series[key].areaStyle = {
  377. opacity: 0,
  378. };
  379. }
  380. series[key].lineStyle = {
  381. width: optionsSetup.lineWidth,
  382. };
  383. series[key].itemStyle.borderRadius = optionsSetup.radius;
  384. series[key].label = {
  385. show: optionsSetup.isShowLine,
  386. position: optionsSetup.fontPositionLine,
  387. distance: optionsSetup.fontDistanceLine,
  388. fontSize: optionsSetup.fontSizeLine,
  389. color: optionsSetup.fontColorLine,
  390. fontWeight: optionsSetup.fontWeightLine,
  391. formatter: !!optionsSetup.percentSignLine ? '{c}%' : '{c}',
  392. fontStyle: optionsSetup.fontStyleLine,
  393. fontFamily: optionsSetup.fontFamilyLine,
  394. };
  395. }
  396. }
  397. this.options.series = series;
  398. },
  399. // 柱体设置 数值设置
  400. setOptionsBar() {
  401. const optionsSetup = this.optionsSetup;
  402. const series = this.options.series;
  403. for (const key in series) {
  404. if (series[key].type === "bar") {
  405. series[key].label = {
  406. show: optionsSetup.isShowBar,
  407. position: optionsSetup.fontPositionBar,
  408. distance: optionsSetup.fontDistanceBar,
  409. fontSize: optionsSetup.fontSizeBar,
  410. color: optionsSetup.fontColorBar,
  411. fontWeight: optionsSetup.fontWeightBar,
  412. formatter: !!optionsSetup.percentSignBar ? '{c}%' : '{c}',
  413. fontStyle: optionsSetup.fontStyleBar,
  414. fontFamily: optionsSetup.fontFamilyBar,
  415. };
  416. //柱体背景属性
  417. series[key].showBackground = optionsSetup.isShowBackground;
  418. series[key].backgroundStyle = {
  419. color: optionsSetup.backgroundStyleColor,
  420. borderColor: optionsSetup.backgroundStyleBorderColor,
  421. borderWidth: optionsSetup.backgroundStyleBorderWidth,
  422. borderType: optionsSetup.backgroundStyleBorderType,
  423. shadowBlur: optionsSetup.backgroundStyleShadowBlur,
  424. shadowColor: optionsSetup.backgroundStyleShadowColor,
  425. opacity: optionsSetup.backgroundStyleOpacity / 100,
  426. };
  427. series[key].barWidth = optionsSetup.maxWidth;
  428. series[key].barMinHeight = optionsSetup.minHeight;
  429. series[key].itemStyle.barBorderRadius = optionsSetup.radius;
  430. }
  431. }
  432. this.options.series = series;
  433. },
  434. // tooltip 设置
  435. setOptionsTooltip() {
  436. const optionsSetup = this.optionsSetup;
  437. const tooltip = {
  438. show: optionsSetup.isShowTooltip,
  439. trigger: optionsSetup.tooltipTrigger,
  440. axisPointer: {
  441. type: optionsSetup.tooltipAxisPointerType,
  442. },
  443. backgroundColor: optionsSetup.tooltipBackgroundColor,
  444. borderColor: optionsSetup.tooltipBorderColor,
  445. borderWidth: optionsSetup.tooltipBorderWidth,
  446. textStyle: {
  447. color: optionsSetup.tooltipColor,
  448. fontSize: optionsSetup.tooltipFontSize,
  449. fontWeight: optionsSetup.tooltipFontWeight,
  450. fontStyle: optionsSetup.tooltipFontStyle,
  451. fontFamily: optionsSetup.tooltipFontFamily,
  452. },
  453. };
  454. this.options.tooltip = tooltip;
  455. },
  456. // 边距设置
  457. setOptionsMargin() {
  458. const optionsSetup = this.optionsSetup;
  459. const grid = {
  460. left: optionsSetup.marginLeft,
  461. right: optionsSetup.marginRight,
  462. bottom: optionsSetup.marginBottom,
  463. top: optionsSetup.marginTop,
  464. containLabel: true,
  465. };
  466. this.options.grid = grid;
  467. },
  468. setOptionsLegend() {
  469. const optionsSetup = this.optionsSetup;
  470. const legend = {
  471. show: optionsSetup.isShowLegend,
  472. left: optionsSetup.lateralPosition,
  473. //right: optionsSetup.lateralPosition,
  474. top: optionsSetup.longitudinalPosition,
  475. //bottom: optionsSetup.longitudinalPosition,
  476. orient: optionsSetup.layoutFront,
  477. textStyle: {
  478. color: optionsSetup.legendColor,
  479. fontSize: optionsSetup.legendFontSize,
  480. fontWeight: optionsSetup.legendFontWeight,
  481. fontStyle: optionsSetup.legendFontStyle,
  482. fontFamily: optionsSetup.legendFontFamily,
  483. },
  484. itemHeight: optionsSetup.legendHeight,
  485. itemWidth: optionsSetup.legendWidth,
  486. };
  487. this.options.legend = legend;
  488. },
  489. // 图例名称设置
  490. setOptionsLegendName(name) {
  491. const optionsSetup = this.optionsSetup;
  492. const series = this.options.series;
  493. const legendName = optionsSetup.legendName;
  494. // 图例没有手动写则显示原值,写了则显示新值
  495. if (null == legendName || legendName === "") {
  496. for (let i = 0; i < name.length; i++) {
  497. series[i].name = name[i];
  498. }
  499. this.options.legend["data"] = name;
  500. } else {
  501. const arr = legendName.split("|");
  502. for (let i = 0; i < arr.length; i++) {
  503. series[i].name = arr[i];
  504. }
  505. this.options.legend["data"] = arr;
  506. }
  507. },
  508. // 图例颜色修改
  509. setOptionsColor() {
  510. const optionsSetup = this.optionsSetup;
  511. const customColor = optionsSetup.customColor;
  512. if (!customColor) return;
  513. const arrColor = [];
  514. for (let i = 0; i < customColor.length; i++) {
  515. arrColor.push(customColor[i].color);
  516. }
  517. this.options.color = arrColor;
  518. this.options = Object.assign({}, this.options);
  519. },
  520. // 数据处理
  521. setOptionsData(e, paramsConfig) {
  522. const optionsData = this.optionsData; // 数据类型 静态 or 动态
  523. // 联动接收者逻辑开始
  524. optionsData.dynamicData = optionsData.dynamicData || {}; // 兼容 dynamicData undefined
  525. const myDynamicData = optionsData.dynamicData;
  526. clearInterval(this.flagInter); // 不管咋,先干掉上一次的定时任务,避免多跑
  527. if (
  528. e &&
  529. optionsData.dataType !== "staticData" &&
  530. Object.keys(myDynamicData.contextData).length
  531. ) {
  532. const keyArr = Object.keys(myDynamicData.contextData);
  533. paramsConfig.forEach((conf) => {
  534. if (keyArr.includes(conf.targetKey)) {
  535. myDynamicData.contextData[conf.targetKey] = e[conf.originKey];
  536. }
  537. });
  538. }
  539. // 联动接收者逻辑结束
  540. optionsData.dataType === "staticData"
  541. ? this.staticDataFn(optionsData.staticData)
  542. : this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
  543. },
  544. staticDataFn(val) {
  545. const series = this.options.series;
  546. let axis = [];
  547. let bar = [];
  548. let line = [];
  549. for (const i in val) {
  550. axis[i] = val[i].axis;
  551. bar[i] = val[i].bar;
  552. line[i] = val[i].line;
  553. }
  554. // x轴
  555. this.options.xAxis.data = axis;
  556. // series
  557. for (const i in series) {
  558. if (series[i].type === "bar") {
  559. series[i].data = bar;
  560. } else {
  561. series[i].data = line;
  562. }
  563. }
  564. const legendName = [];
  565. legendName.push("bar");
  566. legendName.push("line");
  567. const optionsSetup = this.optionsSetup;
  568. // 根据图表的宽度 x轴的字体大小、长度来估算X轴的label能展示多少个字
  569. const rowsNum = optionsSetup.textRowsNum !== "" ? optionsSetup.textRowsNum : parseInt((this.optionsStyle.width / axis.length) / optionsSetup.textFontSizeX);
  570. const axisLabel = {
  571. show: optionsSetup.isShowAxisLabelX,
  572. interval: optionsSetup.textIntervalX,
  573. // 文字角度
  574. rotate: optionsSetup.textAngleX,
  575. textStyle: {
  576. // 坐标文字颜色
  577. color: optionsSetup.textColorX,
  578. fontSize: optionsSetup.textFontSizeX,
  579. fontWeight: optionsSetup.textFontWeightX,
  580. fontStyle: optionsSetup.textFontStyleX,
  581. fontFamily: optionsSetup.textFontFamilyX,
  582. },
  583. // 自动换行
  584. formatter: function (value, index) {
  585. const strs = value.split('');
  586. let str = ''
  587. for (let i = 0, s; s = strs[i++];) {
  588. str += s;
  589. if (!(i % rowsNum)) str += '\n';
  590. }
  591. return str
  592. }
  593. }
  594. if (optionsSetup.textRowsBreakAuto) {
  595. this.options.xAxis.axisLabel = axisLabel;
  596. }
  597. this.options.legend["data"] = legendName;
  598. this.setOptionsLegendName(legendName);
  599. },
  600. dynamicDataFn(val, refreshTime) {
  601. if (!val) return;
  602. if (this.ispreview) {
  603. this.getEchartData(val);
  604. this.flagInter = setInterval(() => {
  605. this.getEchartData(val);
  606. }, refreshTime);
  607. } else {
  608. this.getEchartData(val);
  609. }
  610. },
  611. getEchartData(val) {
  612. const data = this.queryEchartsData(val);
  613. data.then((res) => {
  614. this.renderingFn(res);
  615. });
  616. },
  617. renderingFn(val) {
  618. this.options.xAxis.data = val.xAxis;
  619. // series
  620. const series = this.options.series;
  621. const legendName = [];
  622. for (const i in series) {
  623. for (const j in val.series) {
  624. if (series[i].type === val.series[j].type) {
  625. series[i].data = val.series[j].data;
  626. legendName.push(val.series[j].name);
  627. }
  628. }
  629. }
  630. const optionsSetup = this.optionsSetup;
  631. // 根据图表的宽度 x轴的字体大小、长度来估算X轴的label能展示多少个字
  632. const xAxisDataLength = val.length !== 0 ? val.xAxis.length : 1;
  633. const rowsNum = optionsSetup.textRowsNum !== "" ? optionsSetup.textRowsNum : parseInt((this.optionsStyle.width / xAxisDataLength) / optionsSetup.textFontSizeX);
  634. const axisLabel = {
  635. show: optionsSetup.isShowAxisLabelX,
  636. interval: optionsSetup.textIntervalX,
  637. // 文字角度
  638. rotate: optionsSetup.textAngleX,
  639. textStyle: {
  640. // 坐标文字颜色
  641. color: optionsSetup.textColorX,
  642. fontSize: optionsSetup.textFontSizeX,
  643. fontWeight: optionsSetup.textFontWeightX,
  644. fontStyle: optionsSetup.textFontStyleX,
  645. fontFamily: optionsSetup.textFontFamilyX,
  646. },
  647. // 自动换行
  648. formatter: function (value, index) {
  649. const strs = value.split('');
  650. let str = ''
  651. for (let i = 0, s; s = strs[i++];) {
  652. str += s;
  653. if (!(i % rowsNum)) str += '\n';
  654. }
  655. return str
  656. }
  657. }
  658. if (optionsSetup.textRowsBreakAuto) {
  659. this.options.xAxis.axisLabel = axisLabel;
  660. }
  661. this.options.legend["data"] = legendName;
  662. this.setOptionsLegendName(legendName);
  663. },
  664. },
  665. };
  666. </script>
  667. <style scoped lang="scss">
  668. .echarts {
  669. width: 100%;
  670. height: 100%;
  671. overflow: hidden;
  672. }
  673. </style>