column-with-rotated-data-labels.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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>Column with rotate negative Data Labels</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/apexcharts"></script>
  30. </head>
  31. <body>
  32. <div id="chart"></div>
  33. <script>
  34. var options = {
  35. series: [{
  36. name: 'Cash Flow',
  37. data: [1.45, 5.42, 5.9, -0.42, -12.6, -18.1, -18.2, -14.16, -11.1, -6.09, 0.34, 3.88, 13.07,
  38. 5.8, 2, 7.37, 8.1, 13.57, 15.75, 17.1, 19.8, -27.03, -54.4, -47.2, -43.3, -18.6, -
  39. 48.6, -41.1, -39.6, -37.6, -29.4, -21.4, -2.4
  40. ]
  41. }],
  42. chart: {
  43. type: 'bar',
  44. height: 350
  45. },
  46. plotOptions: {
  47. bar: {
  48. colors: {
  49. ranges: [{
  50. from: -100,
  51. to: -46,
  52. color: '#F15B46'
  53. }, {
  54. from: -45,
  55. to: 0,
  56. color: '#FEB019'
  57. }]
  58. },
  59. columnWidth: '80%',
  60. dataLabels: {
  61. orientation: 'vertical',
  62. position: 'top' // top, center, bottom
  63. },
  64. }
  65. },
  66. dataLabels: {
  67. enabled: true,
  68. style: {
  69. fontSize: '12px',
  70. colors: ["#000000"]
  71. }
  72. },
  73. yaxis: {
  74. title: {
  75. text: 'Growth',
  76. },
  77. labels: {
  78. formatter: function (y) {
  79. return y.toFixed(0) + "%";
  80. }
  81. }
  82. },
  83. xaxis: {
  84. type: 'category',
  85. categories: [
  86. '2011-01-01', '2011-02-01', '2011-03-01', '2011-04-01', '2011-05-01', '2011-06-01',
  87. '2011-07-01', '2011-08-01', '2011-09-01', '2011-10-01', '2011-11-01', '2011-12-01',
  88. '2012-01-01', '2012-02-01', '2012-03-01', '2012-04-01', '2012-05-01', '2012-06-01',
  89. '2012-07-01', '2012-08-01', '2012-09-01', '2012-10-01', '2012-11-01', '2012-12-01',
  90. '2013-01-01', '2013-02-01', '2013-03-01', '2013-04-01', '2013-05-01', '2013-06-01',
  91. '2013-07-01', '2013-08-01', '2013-09-01'
  92. ],
  93. labels: {
  94. rotate: -90
  95. }
  96. }
  97. };
  98. var chart = new ApexCharts(document.querySelector("#chart"), options);
  99. chart.render();
  100. </script>
  101. </body>
  102. </html>