widgetPieNightingaleRose.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <div :style="styleObj">
  3. <v-chart :options="options" autoresize />
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: "WidgetPieNightingaleRoseArea", //南丁格尔玫瑰图面积模式 参考:https://echarts.apache.org/examples/zh/editor.html?c=pie-roseType-simple
  9. components: {},
  10. props: {
  11. value: Object,
  12. ispreview: Boolean,
  13. },
  14. data() {
  15. return {
  16. options: {
  17. legend: {
  18. top: "bottom",
  19. },
  20. toolbox: {
  21. show: true,
  22. feature: {
  23. mark: { show: true },
  24. },
  25. },
  26. series: [
  27. {
  28. //name: "面积模式",
  29. type: "pie",
  30. radius: ["10%", "50%"],
  31. center: ["50%", "50%"],
  32. roseType: "area",
  33. itemStyle: {
  34. borderRadius: 8,
  35. },
  36. data: [],
  37. },
  38. ],
  39. },
  40. optionsStyle: {}, // 样式
  41. optionsData: {}, // 数据
  42. optionsCollapse: {}, // 图标属性
  43. optionsSetup: {},
  44. };
  45. },
  46. computed: {
  47. styleObj() {
  48. return {
  49. position: this.ispreview ? "absolute" : "static",
  50. width: this.optionsStyle.width + "px",
  51. height: this.optionsStyle.height + "px",
  52. left: this.optionsStyle.left + "px",
  53. top: this.optionsStyle.top + "px",
  54. background: this.optionsSetup.background,
  55. };
  56. },
  57. },
  58. watch: {
  59. value: {
  60. handler(val) {
  61. this.optionsStyle = val.position;
  62. this.optionsData = val.data;
  63. this.optionsCollapse = val.setup;
  64. this.optionsSetup = val.setup;
  65. this.editorOptions();
  66. },
  67. deep: true,
  68. },
  69. },
  70. mounted() {
  71. this.optionsStyle = this.value.position;
  72. this.optionsData = this.value.data;
  73. this.optionsCollapse = this.value.setup;
  74. this.optionsSetup = this.value.setup;
  75. this.editorOptions();
  76. },
  77. methods: {
  78. // 修改图标options属性
  79. editorOptions() {
  80. this.setOptionsTitle();
  81. this.setOptionsValue();
  82. this.setOptionsTooltip();
  83. this.setOptionsLegend();
  84. this.setOptionsColor();
  85. this.setOptionsData();
  86. this.setOptionsRosetype();
  87. },
  88. // 饼图模式 面积模式"area" 半径模式"radius"
  89. setOptionsRosetype() {
  90. this.options.series[0]["roseType"] = this.optionsSetup.nightingleRosetype;
  91. },
  92. // 标题修改
  93. setOptionsTitle() {
  94. const optionsSetup = this.optionsSetup;
  95. const title = {};
  96. title.text = optionsSetup.titleText;
  97. title.show = optionsSetup.isNoTitle;
  98. title.left = optionsSetup.textAlign;
  99. title.textStyle = {
  100. color: optionsSetup.textColor,
  101. fontSize: optionsSetup.textFontSize,
  102. fontWeight: optionsSetup.textFontWeight,
  103. fontStyle: optionsSetup.textFontStyle,
  104. };
  105. title.subtext = optionsSetup.subText;
  106. title.subtextStyle = {
  107. color: optionsSetup.subTextColor,
  108. fontWeight: optionsSetup.subTextFontWeight,
  109. fontSize: optionsSetup.subTextFontSize,
  110. fontStyle: optionsSetup.subTextFontStyle,
  111. };
  112. this.options.title = title;
  113. },
  114. // 数值设定
  115. setOptionsValue() {
  116. const optionsSetup = this.optionsSetup;
  117. const series = this.options.series;
  118. const numberValue = optionsSetup.numberValue ? "{c}" : "";
  119. const percentage = optionsSetup.percentage ? "({d})%" : "";
  120. const label = {
  121. show: optionsSetup.isShow,
  122. formatter: `{a|{b}:${numberValue} ${percentage}}`,
  123. rich: {
  124. a: {
  125. padding: [-30, 15, -20, 15],
  126. color: optionsSetup.subTextColor,
  127. fontSize: optionsSetup.fontSize,
  128. fontWeight: optionsSetup.fontWeight,
  129. },
  130. },
  131. fontSize: optionsSetup.fontSize,
  132. fontWeight: optionsSetup.optionsSetup,
  133. };
  134. for (const key in series) {
  135. if (series[key].type == "pie") {
  136. series[key].label = label;
  137. series[key].labelLine = { show: optionsSetup.isShow };
  138. }
  139. }
  140. },
  141. // tooltip 设置
  142. setOptionsTooltip() {
  143. const optionsSetup = this.optionsSetup;
  144. const tooltip = {
  145. trigger: "item",
  146. show: true,
  147. textStyle: {
  148. color: optionsSetup.tipsColor,
  149. fontSize: optionsSetup.tipsFontSize,
  150. },
  151. };
  152. this.options.tooltip = tooltip;
  153. },
  154. // 边距设置
  155. setOptionsMargin() {
  156. const optionsSetup = this.optionsSetup;
  157. const grid = {
  158. left: optionsSetup.marginLeft,
  159. right: optionsSetup.marginRight,
  160. bottom: optionsSetup.marginBottom,
  161. top: optionsSetup.marginTop,
  162. containLabel: true,
  163. };
  164. this.options.grid = grid;
  165. },
  166. // 图例操作 legend
  167. setOptionsLegend() {
  168. const optionsSetup = this.optionsSetup;
  169. const legend = this.options.legend;
  170. legend.show = optionsSetup.isShowLegend;
  171. legend.left = optionsSetup.lateralPosition == "left" ? 0 : "auto";
  172. legend.right = optionsSetup.lateralPosition == "right" ? 0 : "auto";
  173. legend.top = optionsSetup.longitudinalPosition == "top" ? 0 : "auto";
  174. legend.bottom =
  175. optionsSetup.longitudinalPosition == "bottom" ? 0 : "auto";
  176. legend.orient = optionsSetup.layoutFront;
  177. legend.textStyle = {
  178. color: optionsSetup.legendColor,
  179. fontSize: optionsSetup.legendFontSize,
  180. };
  181. legend.itemWidth = optionsSetup.legendWidth;
  182. },
  183. // 图例颜色修改
  184. setOptionsColor() {
  185. const optionsSetup = this.optionsSetup;
  186. const customColor = optionsSetup.customColor;
  187. if (!customColor) return;
  188. const arrColor = [];
  189. for (let i = 0; i < customColor.length; i++) {
  190. arrColor.push(customColor[i].color);
  191. }
  192. this.options.color = arrColor;
  193. this.options = Object.assign({}, this.options);
  194. },
  195. // 数据解析
  196. setOptionsData() {
  197. const optionsData = this.optionsData; // 数据类型 静态 or 动态
  198. optionsData.dataType == "staticData"
  199. ? this.staticDataFn(optionsData.staticData)
  200. : this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
  201. },
  202. staticDataFn(val) {
  203. const staticData = typeof val == "string" ? JSON.parse(val) : val;
  204. for (const key in this.options.series) {
  205. if (this.options.series[key].type == "pie") {
  206. this.options.series[key].data = staticData;
  207. }
  208. }
  209. },
  210. dynamicDataFn(val, refreshTime) {
  211. if (!val) return;
  212. if (this.ispreview) {
  213. this.getEchartData(val);
  214. this.flagInter = setInterval(() => {
  215. this.getEchartData(val);
  216. }, refreshTime);
  217. } else {
  218. this.getEchartData(val);
  219. }
  220. },
  221. getEchartData(val) {
  222. const data = this.queryEchartsData(val);
  223. data.then((res) => {
  224. this.renderingFn(res);
  225. });
  226. },
  227. renderingFn(val) {
  228. for (const key in this.options.series) {
  229. if (this.options.series[key].type == "pie") {
  230. this.options.series[key].data = val;
  231. }
  232. }
  233. },
  234. },
  235. };
  236. </script>
  237. <style scoped lang="scss">
  238. .echarts {
  239. width: 100%;
  240. height: 100%;
  241. overflow: hidden;
  242. }
  243. </style>