donut-update.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  7. <title>Simple Pie</title>
  8. <link href="../../assets/styles.css" rel="stylesheet" />
  9. <style>
  10. #chart {
  11. max-width: 480px;
  12. margin: 35px auto;
  13. padding: 0;
  14. }
  15. .actions {
  16. top: -10px;
  17. position: relative;
  18. z-index: 10;
  19. max-width: 400px;
  20. margin: 0 auto;
  21. }
  22. button {
  23. color: #fff;
  24. background: #20b2aa;
  25. padding: 5px 10px;
  26. margin: 2px;
  27. font-weight: bold;
  28. font-size: 13px;
  29. border-radius: 5px;
  30. }
  31. p {
  32. margin: 10px 0;
  33. }
  34. @media only screen and (max-width: 480px) {
  35. .actions {
  36. margin-top: 0;
  37. left: 0
  38. }
  39. }
  40. </style>
  41. <script>
  42. window.Promise ||
  43. document.write(
  44. '<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"><\/script>'
  45. )
  46. window.Promise ||
  47. document.write(
  48. '<script src="https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill@1.2.20171210/classList.min.js"><\/script>'
  49. )
  50. window.Promise ||
  51. document.write(
  52. '<script src="https://cdn.jsdelivr.net/npm/findindex_polyfill_mdn"><\/script>'
  53. )
  54. </script>
  55. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
  56. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  57. <script src="https://cdn.jsdelivr.net/npm/vue-apexcharts"></script>
  58. </head>
  59. <body>
  60. <div id="app">
  61. <div>
  62. <div class="chart-wrap">
  63. <div id="chart">
  64. <apexchart type="donut" width="380" :options="chartOptions" :series="series"></apexchart>
  65. </div>
  66. </div>
  67. <div class="actions">
  68. <button
  69. @click="appendData">
  70. + ADD
  71. </button>
  72. <button
  73. @click="removeData">
  74. - REMOVE
  75. </button>
  76. <button
  77. @click="randomize">
  78. RANDOMIZE
  79. </button>
  80. <button
  81. @click="reset">
  82. RESET
  83. </button>
  84. </div>
  85. </div>
  86. </div>
  87. <!-- Below element is just for displaying source code. it is not required. DO NOT USE -->
  88. <div id="html">
  89. &lt;div&gt;
  90. &lt;div class=&quot;chart-wrap&quot;&gt;
  91. &lt;div id=&quot;chart&quot;&gt;
  92. &lt;apexchart type=&quot;donut&quot; width=&quot;380&quot; :options=&quot;chartOptions&quot; :series=&quot;series&quot;&gt;&lt;/apexchart&gt;
  93. &lt;/div&gt;
  94. &lt;/div&gt;
  95. &lt;div class=&quot;actions&quot;&gt;
  96. &lt;button
  97. @click=&quot;appendData&quot;&gt;
  98. + ADD
  99. &lt;/button&gt;
  100. &lt;button
  101. @click=&quot;removeData&quot;&gt;
  102. - REMOVE
  103. &lt;/button&gt;
  104. &lt;button
  105. @click=&quot;randomize&quot;&gt;
  106. RANDOMIZE
  107. &lt;/button&gt;
  108. &lt;button
  109. @click=&quot;reset&quot;&gt;
  110. RESET
  111. &lt;/button&gt;
  112. &lt;/div&gt;
  113. &lt;/div&gt;
  114. </div>
  115. <script>
  116. new Vue({
  117. el: '#app',
  118. components: {
  119. apexchart: VueApexCharts,
  120. },
  121. data: {
  122. series: [44, 55, 13, 33],
  123. chartOptions: {
  124. chart: {
  125. width: 380,
  126. type: 'donut',
  127. },
  128. dataLabels: {
  129. enabled: false
  130. },
  131. responsive: [{
  132. breakpoint: 480,
  133. options: {
  134. chart: {
  135. width: 200
  136. },
  137. legend: {
  138. show: false
  139. }
  140. }
  141. }],
  142. legend: {
  143. position: 'right',
  144. offsetY: 0,
  145. height: 230,
  146. }
  147. },
  148. },
  149. methods: {
  150. appendData: function () {
  151. var arr = this.series.slice()
  152. arr.push(Math.floor(Math.random() * (100 - 1 + 1)) + 1)
  153. this.series = arr
  154. },
  155. removeData: function () {
  156. if(this.series.length === 1) return
  157. var arr = this.series.slice()
  158. arr.pop()
  159. this.series = arr
  160. },
  161. randomize: function () {
  162. this.series = this.series.map(function() {
  163. return Math.floor(Math.random() * (100 - 1 + 1)) + 1
  164. })
  165. },
  166. reset: function () {
  167. this.series = [44, 55, 13, 33]
  168. }
  169. },
  170. })
  171. </script>
  172. </body>
  173. </html>