widgetPieNightingaleRose.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. };
  104. title.subtext = optionsSetup.subText;
  105. title.subtextStyle = {
  106. color: optionsSetup.subTextColor,
  107. fontWeight: optionsSetup.subTextFontWeight,
  108. fontSize: optionsSetup.subTextFontSize
  109. };
  110. this.options.title = title;
  111. },
  112. // 数值设定
  113. setOptionsValue() {
  114. const optionsSetup = this.optionsSetup;
  115. const series = this.options.series;
  116. const numberValue = optionsSetup.numberValue ? "{c}" : "";
  117. const percentage = optionsSetup.percentage ? "({d})%" : "";
  118. const label = {
  119. show: optionsSetup.isShow,
  120. formatter: `{a|{b}:${numberValue} ${percentage}}`,
  121. rich: {
  122. a: {
  123. padding: [-30, 15, -20, 15],
  124. color: optionsSetup.subTextColor,
  125. fontSize: optionsSetup.fontSize,
  126. fontWeight: optionsSetup.fontWeight
  127. }
  128. },
  129. fontSize: optionsSetup.fontSize,
  130. fontWeight: optionsSetup.optionsSetup
  131. };
  132. for (const key in series) {
  133. if (series[key].type == "pie") {
  134. series[key].label = label;
  135. series[key].labelLine = { show: optionsSetup.isShow };
  136. }
  137. }
  138. },
  139. // tooltip 设置
  140. setOptionsTooltip() {
  141. const optionsSetup = this.optionsSetup;
  142. const tooltip = {
  143. trigger: "item",
  144. show: true,
  145. textStyle: {
  146. color: optionsSetup.tipsColor,
  147. fontSize: optionsSetup.tipsFontSize
  148. }
  149. };
  150. this.options.tooltip = tooltip;
  151. },
  152. // 边距设置
  153. setOptionsMargin() {
  154. const optionsSetup = this.optionsSetup;
  155. const grid = {
  156. left: optionsSetup.marginLeft,
  157. right: optionsSetup.marginRight,
  158. bottom: optionsSetup.marginBottom,
  159. top: optionsSetup.marginTop,
  160. containLabel: true
  161. };
  162. this.options.grid = grid;
  163. },
  164. // 图例操作 legend
  165. setOptionsLegend() {
  166. const optionsSetup = this.optionsSetup;
  167. const legend = this.options.legend;
  168. legend.show = optionsSetup.isShowLegend;
  169. legend.left = optionsSetup.lateralPosition == "left" ? 0 : "auto";
  170. legend.right = optionsSetup.lateralPosition == "right" ? 0 : "auto";
  171. legend.top = optionsSetup.longitudinalPosition == "top" ? 0 : "auto";
  172. legend.bottom =
  173. optionsSetup.longitudinalPosition == "bottom" ? 0 : "auto";
  174. legend.orient = optionsSetup.layoutFront;
  175. legend.textStyle = {
  176. color: optionsSetup.legendColor,
  177. fontSize: optionsSetup.fontSize
  178. };
  179. legend.itemWidth = optionsSetup.legendWidth;
  180. },
  181. // 图例颜色修改
  182. setOptionsColor() {
  183. const optionsSetup = this.optionsSetup;
  184. const customColor = optionsSetup.customColor;
  185. if (!customColor) return;
  186. const arrColor = [];
  187. for (let i = 0; i < customColor.length; i++) {
  188. arrColor.push(customColor[i].color);
  189. }
  190. this.options.color = arrColor;
  191. this.options = Object.assign({}, this.options);
  192. },
  193. // 数据解析
  194. setOptionsData() {
  195. const optionsData = this.optionsData; // 数据类型 静态 or 动态
  196. optionsData.dataType == "staticData"
  197. ? this.staticDataFn(optionsData.staticData)
  198. : this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
  199. },
  200. staticDataFn(val) {
  201. const staticData = typeof val == "string" ? JSON.parse(val) : val;
  202. for (const key in this.options.series) {
  203. if (this.options.series[key].type == "pie") {
  204. this.options.series[key].data = staticData;
  205. }
  206. }
  207. },
  208. dynamicDataFn(val, refreshTime) {
  209. if (!val) return;
  210. if (this.ispreview) {
  211. this.getEchartData(val);
  212. this.flagInter = setInterval(() => {
  213. this.getEchartData(val);
  214. }, refreshTime);
  215. } else {
  216. this.getEchartData(val);
  217. }
  218. },
  219. getEchartData(val) {
  220. const data = this.queryEchartsData(val);
  221. data.then(res => {
  222. this.renderingFn(res);
  223. });
  224. },
  225. renderingFn(val) {
  226. for (const key in this.options.series) {
  227. if (this.options.series[key].type == "pie") {
  228. this.options.series[key].data = val;
  229. }
  230. }
  231. }
  232. }
  233. };
  234. </script>
  235. <style scoped lang="scss">
  236. .echarts {
  237. width: 100%;
  238. height: 100%;
  239. overflow: hidden;
  240. }
  241. </style>