demo.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <link rel="icon" href="https://jscdn.com.cn/highcharts/images/favicon.ico" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1" />
  7. <style>
  8. /* css 代码 */
  9. </style>
  10. <script src="./libs/vue@2.7.10.js"></script>
  11. <script src="./libs/datav.min.js"></script>
  12. <script src="./libs/echarts.min2.js"></script>
  13. <script src="./libs/echarts-gl.min.js"></script>
  14. <script src="./libs/element-ui@2.15.9.js"></script>
  15. <script src="./libs/axios.min.js"></script>
  16. <script src="./js/request.js"></script>
  17. <script src="./js/data.js"></script>
  18. <script src="./libs/vue-seamless-scroll.min.js"></script>
  19. <script src="./libs/echarts-tooltip-carousel.js"></script>
  20. <!-- highchair -->
  21. <script src="./libs/highcharts.js"></script>
  22. <script src="./libs/highcharts3d.js"></script>
  23. </head>
  24. <body>
  25. <div id="app" class="big-box">
  26. <div class="com-container" ref="container" style="width:380px;height:300px;">
  27. </div>
  28. <div class="tulibox">
  29. <div v-for="(item,index) in peiData" :key="index" class="tuliboxitem">
  30. <span class="name">{{item.name}}</span> <span class="value">{{item.y}}%</span>
  31. </div>
  32. </div>
  33. </div>
  34. <script>
  35. console.log(Highcharts)
  36. var highcharts = Highcharts
  37. let app = new Vue({
  38. el: '#app',
  39. data () {
  40. return {
  41. peiData: [
  42. { name: '输电', y: 28, h: 60 },
  43. { name: '变电', y: 20, h: 20 },
  44. { name: '配电', y: 10, h: 32 },
  45. { name: '新业务', y: 6, h: 45 }
  46. ],
  47. each:'',
  48. wrap: '',
  49. prototype: '',
  50. }
  51. },
  52. mounted () {
  53. this.each = highcharts.each
  54. this.wrap = highcharts
  55. this.prototype = highcharts.seriesTypes.pie.prototype
  56. this.initChart()
  57. const that = this
  58. window.onresize = function () { that.initChart() }
  59. },
  60. methods: {
  61. initChart () {
  62. // 修改3d饼图绘制过程
  63. const round = Math.round
  64. const cos = Math.cos
  65. const sin = Math.sin
  66. const deg2rad = Math.deg2rad
  67. let that = this
  68. highcharts.wrap(this.prototype, 'translate', function (proceed) {
  69. proceed.apply(this, [].slice.call(arguments, 1))
  70. // Do not do this if the chart is not 3D
  71. if (!this.chart.is3d()) {
  72. return
  73. }
  74. const series = this
  75. const chart = series.chart
  76. const options = chart.options
  77. const seriesOptions = series.options
  78. const depth = seriesOptions.depth || 0
  79. const options3d = options.chart.options3d
  80. const alpha = options3d.alpha
  81. const beta = options3d.beta
  82. var z = seriesOptions.stacking ? (seriesOptions.stack || 0) * depth : series._i * depth
  83. z += depth / 2
  84. if (seriesOptions.grouping !== false) {
  85. z = 0
  86. }
  87. that.each(series.data, function (point) {
  88. const shapeArgs = point.shapeArgs
  89. var angle
  90. point.shapeType = 'arc3d'
  91. var ran = point.options.h
  92. shapeArgs.z = z
  93. shapeArgs.depth = depth * 0.75 + ran
  94. shapeArgs.alpha = alpha
  95. shapeArgs.beta = beta
  96. shapeArgs.center = series.center
  97. shapeArgs.ran = ran
  98. angle = (shapeArgs.end + shapeArgs.start) / 2
  99. point.slicedTranslation = {
  100. translateX: round(cos(angle) * seriesOptions.slicedOffset * cos(alpha * deg2rad)),
  101. translateY: round(sin(angle) * seriesOptions.slicedOffset * cos(alpha * deg2rad))
  102. }
  103. })
  104. });
  105. (function (H) {
  106. H.wrap(highcharts.SVGRenderer.prototype, 'arc3dPath', function (proceed) {
  107. // Run original proceed method
  108. const ret = proceed.apply(this, [].slice.call(arguments, 1))
  109. ret.zTop = (ret.zOut + 0.5) / 100
  110. return ret
  111. })
  112. }(highcharts))
  113. // 生成不同高度的3d饼图
  114. const high = this.$refs.container
  115. highcharts.chart(high, {
  116. chart: {
  117. type: 'pie',
  118. animation: false,
  119. backgroundColor: 'rgba(0,0,0,0)',
  120. events: {
  121. load: function () {
  122. const points = this.series[0].points
  123. that.each(points, function (p, i) {
  124. p.graphic.attr({
  125. translateY: -p.shapeArgs.ran
  126. })
  127. p.graphic.side1.attr({
  128. translateY: -p.shapeArgs.ran
  129. })
  130. p.graphic.side2.attr({
  131. translateY: -p.shapeArgs.ran
  132. })
  133. })
  134. }
  135. },
  136. options3d: {
  137. enabled: true,
  138. alpha: 65
  139. }
  140. },
  141. title: {
  142. show: 'false',
  143. text: null
  144. },
  145. subtitle: {
  146. text: null
  147. },
  148. credits: {
  149. enabled: false
  150. },
  151. legend: { // 【图例】位置样式
  152. backgroundColor: 'rgba(0,0,0,0)',
  153. shadow: false,
  154. layout: 'vertical',
  155. align: 'right', // 水平方向位置
  156. verticalAlign: 'top', // 垂直方向位置
  157. x: 0, // 距离x轴的距离
  158. y: 100, // 距离Y轴的距离
  159. symbolPadding: 10,
  160. symbolHeight: 14,
  161. itemStyle: {
  162. lineHeight: '24px',
  163. fontSize: '16px',
  164. color: '#fff'
  165. },
  166. labelFormatter: function () {
  167. /*
  168. * 格式化函数可用的变量:this, 可以用 console.log(this) 来查看包含的详细信息
  169. * this 代表当前数据列对象,所以默认的实现是 return this.name
  170. */
  171. return this.name + this.h + '%'
  172. }
  173. },
  174. plotOptions: {
  175. pie: {
  176. allowPointSelect: true,
  177. cursor: 'pointer',
  178. depth: 35,
  179. innerSize: 180,
  180. dataLabels: {
  181. enabled: false
  182. },
  183. // 显示图例
  184. showInLegend: false
  185. }
  186. },
  187. series: [{
  188. type: 'pie',
  189. name: '占比',
  190. // h 是高度 y是占的圆环长度
  191. colorByPoint: true,
  192. colors: [
  193. { // 注意!!!如果是柱状图请使用color,如果是面积图请使用fillColor
  194. linearGradient: {
  195. x1: 0,
  196. y1: 1,
  197. x2: 1,
  198. y2: 0
  199. },
  200. stops: [
  201. [0, '#19596d'],
  202. [1, '#2ea1b2']
  203. ]
  204. }, { // 注意!!!如果是柱状图请使用color,如果是面积图请使用fillColor
  205. linearGradient: {
  206. x1: 0,
  207. y1: 1,
  208. x2: 1,
  209. y2: 0
  210. },
  211. stops: [
  212. [0, '#ee7529'],
  213. [1, '#f5a86c']
  214. ]
  215. }, { // 注意!!!如果是柱状图请使用color,如果是面积图请使用fillColor
  216. linearGradient: {
  217. x1: 0,
  218. y1: 1,
  219. x2: 1,
  220. y2: 0
  221. },
  222. stops: [
  223. [0, '#f5c055'],
  224. [1, '#967b3d']
  225. ]
  226. }, { // 注意!!!如果是柱状图请使用color,如果是面积图请使用fillColor
  227. linearGradient: {
  228. x1: 0,
  229. y1: 1,
  230. x2: 1,
  231. y2: 0
  232. },
  233. stops: [
  234. [0, '#2d7bb5'],
  235. [1, '#1a5784']
  236. ]
  237. }],
  238. data: this.peiData
  239. }]
  240. })
  241. }
  242. },
  243. })
  244. </script>
  245. </body>
  246. <style scoped lang="less">
  247. .com-container{
  248. width: 380px;
  249. height: 300px;
  250. padding-right: 20px;
  251. }
  252. .big-box{
  253. display: flex;
  254. background-image: url('../img/dizuo.png');
  255. background-repeat: no-repeat;
  256. background-position: 25px 144px;
  257. padding-top: 20px;
  258. }
  259. .tulibox{
  260. padding-top: 65px;
  261. }
  262. .tuliboxitem{
  263. position: relative;
  264. margin: 10px 0;
  265. }
  266. .name{
  267. font-size: 18px;
  268. color: #FEFEFF;
  269. padding-right: 20px;
  270. }
  271. .value{
  272. font-size: 22px;
  273. color: #0CD2EA;
  274. }
  275. .tuliboxitem::before{
  276. content: "";
  277. position: absolute;
  278. width: 16px;
  279. height: 16px;
  280. top: 7px;
  281. border-radius: 50%;
  282. left: -33px;
  283. }
  284. .tuliboxitem:nth-child(1)::before{
  285. background-color: #fff600;
  286. }
  287. .tuliboxitem:nth-child(2)::before{
  288. background-color: #209FED;
  289. }
  290. .tuliboxitem:nth-child(3)::before{
  291. background-color: #808EC7;
  292. }
  293. .tuliboxitem:nth-child(4)::before{
  294. background-color: #EE6B26;
  295. }
  296. </style>
  297. </html>