add line chart date formatting based on sorted dashboard data
This commit is contained in:
parent
9a5bf23712
commit
dd697b47b5
@ -3,10 +3,11 @@ import ReactApexChart from "react-apexcharts";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
const LineChart = ({
|
||||
seriesData = [],
|
||||
categories = [],
|
||||
colors = ["#1E90FF", "#FF6347"],
|
||||
loading = false
|
||||
seriesData = [],
|
||||
categories = [],
|
||||
colors = ["#1E90FF", "#FF6347"],
|
||||
loading = false,
|
||||
lineChartCategoriesDates = [],
|
||||
}) => {
|
||||
const hasValidData =
|
||||
Array.isArray(seriesData) &&
|
||||
@ -100,11 +101,21 @@ const LineChart = ({
|
||||
tooltip: {
|
||||
enabled: true,
|
||||
x: {
|
||||
formatter: (val, opts) => val
|
||||
formatter: (value, { dataPointIndex }) => {
|
||||
if (
|
||||
lineChartCategoriesDates &&
|
||||
lineChartCategoriesDates.length > dataPointIndex
|
||||
) {
|
||||
return lineChartCategoriesDates[dataPointIndex];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<div className="w-full overflow-x-auto">
|
||||
<ReactApexChart
|
||||
|
@ -82,7 +82,13 @@ const Dashboard = () => {
|
||||
day: "numeric",
|
||||
})
|
||||
);
|
||||
|
||||
const lineChartCategoriesDates = sortedDashboardData.map((d) =>
|
||||
new Date(d.date).toLocaleDateString("en-US", {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
})
|
||||
);
|
||||
return (
|
||||
<div className="container-xxl flex-grow-1 container-p-y">
|
||||
<div className="row gy-4">
|
||||
@ -252,6 +258,7 @@ const Dashboard = () => {
|
||||
seriesData={lineChartSeries}
|
||||
categories={lineChartCategories}
|
||||
loading={isLineChartLoading}
|
||||
lineChartCategoriesDates={lineChartCategoriesDates}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user