ChartdataHome.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 { getPengunjungPublic } from "@/actions/pengunjung";
  7. class ChartdataHome extends Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. dataPengunjung: [],
  12. dataChart: this.ChartSpline,
  13. };
  14. }
  15. componentDidMount = async () => {
  16. const dataPengunjung = await getPengunjungPublic({ bulan: new Date().getMonth() + 1, tahun: new Date().getFullYear() });
  17. this.setState({ dataPengunjung: dataPengunjung.data.map((e) => [e._id.tanggal, e.jumlah_pengunjung]) });
  18. this.setState((prevState) => ({ dataChart: { ...prevState.dataChart, data: [{ ...prevState.dataChart.data[0], data: prevState.dataPengunjung }] } }));
  19. };
  20. ChartSpline = {
  21. data: [
  22. {
  23. // label: "Uniques",
  24. color: "#3e3a8e",
  25. data: [],
  26. },
  27. ],
  28. options: {
  29. series: {
  30. lines: {
  31. show: false,
  32. },
  33. points: {
  34. show: true,
  35. radius: 4,
  36. },
  37. splines: {
  38. show: true,
  39. tension: 0.4,
  40. lineWidth: 1,
  41. fill: 0.5,
  42. },
  43. },
  44. grid: {
  45. borderColor: "#eee",
  46. borderWidth: 1,
  47. hoverable: true,
  48. backgroundColor: "#fcfcfc",
  49. },
  50. tooltip: true,
  51. tooltipOpts: {
  52. content: (label, x, y) => x + " : " + y,
  53. },
  54. xaxis: {
  55. tickColor: "#fcfcfc",
  56. mode: "categories",
  57. },
  58. yaxis: {
  59. min: 0,
  60. // max: 150, // optional: use it for a clear represetation
  61. tickColor: "#eee",
  62. //position: 'right' or 'left',
  63. tickFormatter: (v) => v /* + ' visitors'*/,
  64. },
  65. shadowSize: 0,
  66. },
  67. };
  68. convertMonth = (int) => {
  69. switch (int) {
  70. case 1:
  71. return "Januari";
  72. break;
  73. case 2:
  74. return "Februari";
  75. break;
  76. case 3:
  77. return "Maret";
  78. break;
  79. case 4:
  80. return "April";
  81. break;
  82. case 5:
  83. return "Mei";
  84. break;
  85. case 6:
  86. return "Juni";
  87. break;
  88. case 7:
  89. return "Juli";
  90. break;
  91. case 8:
  92. return "Agustus";
  93. break;
  94. case 9:
  95. return "September";
  96. break;
  97. case 10:
  98. return "Oktober";
  99. break;
  100. case 11:
  101. return "November";
  102. break;
  103. case 12:
  104. return "Desember";
  105. break;
  106. default:
  107. break;
  108. }
  109. };
  110. render() {
  111. return (
  112. <Col lg={12}>
  113. <Card>
  114. <CardBody>
  115. <FlotChart options={this.ChartSpline.options} data={this.state.dataChart.data} className="flot-chart" height="150px" width="300px" />
  116. </CardBody>
  117. <div align="center">
  118. <h5 className="font-weight-bold" style={{ fontSize: "12px", marginTop: "3px" }}>Data Statistik Pengunjung Bulan {`${this.convertMonth(new Date().getMonth() + 1)} ${new Date().getFullYear()}`}</h5>
  119. </div>
  120. </Card>
  121. </Col>
  122. );
  123. }
  124. }
  125. export default ChartdataHome;