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