ChartData.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 Sparkline from "@/components/Common/Sparklines.js";
  5. import FlotChart from "@/components/Charts/Flot.js";
  6. import { connect } from "react-redux";
  7. import { getPengunjung } from "@/actions/pengunjung";
  8. class ChartData extends Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. dataPengunjung: [],
  13. };
  14. }
  15. async componentDidMount() {
  16. const { token } = this.props;
  17. const dataPengunjung = await getPengunjung(token);
  18. this.setState({ dataPengunjung: dataPengunjung.data.map((e) => [e._id.bulan, e.jumlah_pengunjung]) });
  19. }
  20. ChartSpline = {
  21. data: [
  22. {
  23. // label: "Uniques",
  24. color: "#3e3a8e",
  25. data: [
  26. ["Jan", 20],
  27. ["Feb", 90],
  28. ["Mar", 40],
  29. ["Apr", 85],
  30. ["Mei", 59],
  31. ["Jun", 93],
  32. ["Jul", 66],
  33. ["Agu", 86],
  34. ["Sep", 60],
  35. ["Okt", 70],
  36. ["Nov", 60],
  37. ["Des", 30],
  38. ],
  39. },
  40. ],
  41. options: {
  42. series: {
  43. lines: {
  44. show: false,
  45. },
  46. points: {
  47. show: true,
  48. radius: 4,
  49. },
  50. splines: {
  51. show: true,
  52. tension: 0.4,
  53. lineWidth: 1,
  54. fill: 0.5,
  55. },
  56. },
  57. grid: {
  58. borderColor: "#eee",
  59. borderWidth: 1,
  60. hoverable: true,
  61. backgroundColor: "#fcfcfc",
  62. },
  63. tooltip: true,
  64. tooltipOpts: {
  65. content: (label, x, y) => x + " : " + y,
  66. },
  67. xaxis: {
  68. tickColor: "#fcfcfc",
  69. mode: "categories",
  70. },
  71. yaxis: {
  72. min: 0,
  73. max: 150, // optional: use it for a clear represetation
  74. tickColor: "#eee",
  75. //position: 'right' or 'left',
  76. tickFormatter: (v) => v /* + ' visitors'*/,
  77. },
  78. shadowSize: 0,
  79. },
  80. };
  81. render() {
  82. console.log(this.state.dataPengunjung);
  83. return (
  84. <Col lg={12}>
  85. <Card className="card-default">
  86. <CardBody>
  87. <FlotChart options={this.ChartSpline.options} data={this.ChartSpline.data} className="flot-chart" height="250px" />
  88. </CardBody>
  89. <div align="center">
  90. <span>Data Statistik Pengunjung Tahun 2022</span>
  91. </div>
  92. </Card>
  93. </Col>
  94. );
  95. }
  96. }
  97. const mapStateToProps = (state) => ({ token: state.token });
  98. export default connect(mapStateToProps)(ChartData);