stacked-bar.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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>Stacked Bar Chart</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: 'Marine Sprite',
  50. data: [44, 55, 41, 37, 22, 43, 21]
  51. }, {
  52. name: 'Striking Calf',
  53. data: [53, 32, 33, 52, 13, 43, 32]
  54. }, {
  55. name: 'Tank Picture',
  56. data: [12, 17, 11, 9, 15, 11, 20]
  57. }, {
  58. name: 'Bucket Slope',
  59. data: [9, 7, 5, 8, 6, 9, 4]
  60. }, {
  61. name: 'Reborn Kid',
  62. data: [25, 12, 19, 32, 25, 24, 10]
  63. }],
  64. options: {
  65. chart: {
  66. type: 'bar',
  67. height: 350,
  68. stacked: true,
  69. },
  70. plotOptions: {
  71. bar: {
  72. horizontal: true,
  73. },
  74. },
  75. stroke: {
  76. width: 1,
  77. colors: ['#fff']
  78. },
  79. title: {
  80. text: 'Fiction Books Sales'
  81. },
  82. xaxis: {
  83. categories: [2008, 2009, 2010, 2011, 2012, 2013, 2014],
  84. labels: {
  85. formatter: function (val) {
  86. return val + "K"
  87. }
  88. }
  89. },
  90. yaxis: {
  91. title: {
  92. text: undefined
  93. },
  94. },
  95. tooltip: {
  96. y: {
  97. formatter: function (val) {
  98. return val + "K"
  99. }
  100. }
  101. },
  102. fill: {
  103. opacity: 1
  104. },
  105. legend: {
  106. position: 'top',
  107. horizontalAlign: 'left',
  108. offsetX: 40
  109. }
  110. },
  111. };
  112. }
  113. render() {
  114. return (
  115. <div>
  116. <div id="chart">
  117. <ReactApexChart options={this.state.options} series={this.state.series} type="bar" height={350} />
  118. </div>
  119. <div id="html-dist"></div>
  120. </div>
  121. );
  122. }
  123. }
  124. const domContainer = document.querySelector('#app');
  125. ReactDOM.render(React.createElement(ApexChart), domContainer);
  126. </script>
  127. </body>
  128. </html>