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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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/react@16.12/umd/react.production.min.js"></script>
  30. <script src="https://cdn.jsdelivr.net/npm/react-dom@16.12/umd/react-dom.production.min.js"></script>
  31. <script src="https://cdn.jsdelivr.net/npm/prop-types@15.7.2/prop-types.min.js"></script>
  32. <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
  33. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  34. <script src="https://cdn.jsdelivr.net/npm/react-apexcharts@1.3.6/dist/react-apexcharts.iife.min.js"></script>
  35. </head>
  36. <body>
  37. <div id="app"></div>
  38. <div id="html">
  39. &lt;div id=&quot;chart&quot;&gt;
  40. &lt;ReactApexChart options={this.state.options} series={this.state.series} type=&quot;bar&quot; height={350} /&gt;
  41. &lt;/div&gt;
  42. </div>
  43. <script type="text/babel">
  44. class ApexChart extends React.Component {
  45. constructor(props) {
  46. super(props);
  47. this.state = {
  48. series: [{
  49. name: 'Cash Flow',
  50. 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,
  51. 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, -
  52. 48.6, -41.1, -39.6, -37.6, -29.4, -21.4, -2.4
  53. ]
  54. }],
  55. options: {
  56. chart: {
  57. type: 'bar',
  58. height: 350
  59. },
  60. plotOptions: {
  61. bar: {
  62. colors: {
  63. ranges: [{
  64. from: -100,
  65. to: -46,
  66. color: '#F15B46'
  67. }, {
  68. from: -45,
  69. to: 0,
  70. color: '#FEB019'
  71. }]
  72. },
  73. columnWidth: '80%',
  74. dataLabels: {
  75. orientation: 'vertical',
  76. position: 'top' // top, center, bottom
  77. },
  78. }
  79. },
  80. dataLabels: {
  81. enabled: true,
  82. style: {
  83. fontSize: '12px',
  84. colors: ["#000000"]
  85. }
  86. },
  87. yaxis: {
  88. title: {
  89. text: 'Growth',
  90. },
  91. labels: {
  92. formatter: function (y) {
  93. return y.toFixed(0) + "%";
  94. }
  95. }
  96. },
  97. xaxis: {
  98. type: 'category',
  99. categories: [
  100. '2011-01-01', '2011-02-01', '2011-03-01', '2011-04-01', '2011-05-01', '2011-06-01',
  101. '2011-07-01', '2011-08-01', '2011-09-01', '2011-10-01', '2011-11-01', '2011-12-01',
  102. '2012-01-01', '2012-02-01', '2012-03-01', '2012-04-01', '2012-05-01', '2012-06-01',
  103. '2012-07-01', '2012-08-01', '2012-09-01', '2012-10-01', '2012-11-01', '2012-12-01',
  104. '2013-01-01', '2013-02-01', '2013-03-01', '2013-04-01', '2013-05-01', '2013-06-01',
  105. '2013-07-01', '2013-08-01', '2013-09-01'
  106. ],
  107. labels: {
  108. rotate: -90
  109. }
  110. }
  111. },
  112. };
  113. }
  114. render() {
  115. return (
  116. <div>
  117. <div id="chart">
  118. <ReactApexChart options={this.state.options} series={this.state.series} type="bar" height={350} />
  119. </div>
  120. <div id="html-dist"></div>
  121. </div>
  122. );
  123. }
  124. }
  125. const domContainer = document.querySelector('#app');
  126. ReactDOM.render(React.createElement(ApexChart), domContainer);
  127. </script>
  128. </body>
  129. </html>