ChartDataBar.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React, { Component } from "react";
  2. import ContentWrapper from "@/components/Layout/ContentWrapper";
  3. import { Container, Row, Col, Card, CardHeader, CardBody } from "reactstrap";
  4. import { connect } from "react-redux";
  5. import { jumlahLaporan } from "@/actions/pelaporan";
  6. import dynamic from "next/dynamic";
  7. const ReactApexChart = dynamic(() => import("react-apexcharts"), { ssr: false });
  8. class ChartDataBar extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. series: [
  13. {
  14. data: [44, 55, 41, 64, 22, 43, 21, 44, 42, 67, 43, 86, 42, 99, 131, 313],
  15. },
  16. ],
  17. options: {
  18. chart: {
  19. type: "bar",
  20. height: 430,
  21. },
  22. plotOptions: {
  23. bar: {
  24. horizontal: true,
  25. dataLabels: {
  26. position: "top",
  27. },
  28. },
  29. },
  30. chart: {
  31. toolbar: {
  32. show: true,
  33. tools: {
  34. download: false,
  35. },
  36. },
  37. },
  38. colors: ["#B2B0D2"],
  39. dataLabels: {
  40. enabled: true,
  41. offsetX: -6,
  42. style: {
  43. fontSize: "12px",
  44. colors: ["#333333"],
  45. },
  46. },
  47. stroke: {
  48. show: true,
  49. width: 1,
  50. colors: ["#fff"],
  51. },
  52. tooltip: {
  53. shared: true,
  54. intersect: false,
  55. },
  56. xaxis: {
  57. categories: ["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI"],
  58. },
  59. },
  60. };
  61. }
  62. async componentDidMount() {
  63. const { token } = this.props;
  64. const data = await jumlahLaporan(token);
  65. console.log(data.data);
  66. }
  67. render() {
  68. return (
  69. <div id="chart">
  70. <ReactApexChart options={this.state.options} series={this.state.series} type="bar" height={430} />
  71. </div>
  72. );
  73. }
  74. }
  75. const MapStateToProps = (state) => ({ token: state.token });
  76. export default connect(MapStateToProps)(ChartDataBar);