bar-with-custom-data-labels.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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>Bar with Custom DataLabels</title>
  8. <link href="../../assets/styles.css" rel="stylesheet" />
  9. <style>
  10. #chart {
  11. max-width: 650px;
  12. margin: 35px auto;
  13. }
  14. </style>
  15. <script>
  16. window.Promise ||
  17. document.write(
  18. '<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"><\/script>'
  19. )
  20. window.Promise ||
  21. document.write(
  22. '<script src="https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill@1.2.20171210/classList.min.js"><\/script>'
  23. )
  24. window.Promise ||
  25. document.write(
  26. '<script src="https://cdn.jsdelivr.net/npm/findindex_polyfill_mdn"><\/script>'
  27. )
  28. </script>
  29. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
  30. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  31. <script src="https://cdn.jsdelivr.net/npm/vue-apexcharts"></script>
  32. </head>
  33. <body>
  34. <div id="app">
  35. <div id="chart">
  36. <apexchart type="bar" height="380" :options="chartOptions" :series="series"></apexchart>
  37. </div>
  38. </div>
  39. <!-- Below element is just for displaying source code. it is not required. DO NOT USE -->
  40. <div id="html">
  41. &lt;div id=&quot;chart&quot;&gt;
  42. &lt;apexchart type=&quot;bar&quot; height=&quot;380&quot; :options=&quot;chartOptions&quot; :series=&quot;series&quot;&gt;&lt;/apexchart&gt;
  43. &lt;/div&gt;
  44. </div>
  45. <script>
  46. new Vue({
  47. el: '#app',
  48. components: {
  49. apexchart: VueApexCharts,
  50. },
  51. data: {
  52. series: [{
  53. data: [400, 430, 448, 470, 540, 580, 690, 1100, 1200, 1380]
  54. }],
  55. chartOptions: {
  56. chart: {
  57. type: 'bar',
  58. height: 380
  59. },
  60. plotOptions: {
  61. bar: {
  62. barHeight: '100%',
  63. distributed: true,
  64. horizontal: true,
  65. dataLabels: {
  66. position: 'bottom'
  67. },
  68. }
  69. },
  70. colors: ['#33b2df', '#546E7A', '#d4526e', '#13d8aa', '#A5978B', '#2b908f', '#f9a3a4', '#90ee7e',
  71. '#f48024', '#69d2e7'
  72. ],
  73. dataLabels: {
  74. enabled: true,
  75. textAnchor: 'start',
  76. style: {
  77. colors: ['#fff']
  78. },
  79. formatter: function (val, opt) {
  80. return opt.w.globals.labels[opt.dataPointIndex] + ": " + val
  81. },
  82. offsetX: 0,
  83. dropShadow: {
  84. enabled: true
  85. }
  86. },
  87. stroke: {
  88. width: 1,
  89. colors: ['#fff']
  90. },
  91. xaxis: {
  92. categories: ['South Korea', 'Canada', 'United Kingdom', 'Netherlands', 'Italy', 'France', 'Japan',
  93. 'United States', 'China', 'India'
  94. ],
  95. },
  96. yaxis: {
  97. labels: {
  98. show: false
  99. }
  100. },
  101. title: {
  102. text: 'Custom DataLabels',
  103. align: 'center',
  104. floating: true
  105. },
  106. subtitle: {
  107. text: 'Category Names as DataLabels inside bars',
  108. align: 'center',
  109. },
  110. tooltip: {
  111. theme: 'dark',
  112. x: {
  113. show: false
  114. },
  115. y: {
  116. title: {
  117. formatter: function () {
  118. return ''
  119. }
  120. }
  121. }
  122. }
  123. },
  124. },
  125. })
  126. </script>
  127. </body>
  128. </html>