feat(HorizontalBarChart): add loading state and improve label positioning
This commit is contained in:
parent
2b24351316
commit
d8a861bb08
@ -9,7 +9,18 @@ const HorizontalBarChart = ({
|
|||||||
"#1E90FF", "#00BFFF", "#9370DB", "#6A0DAD", "#A9A9A9",
|
"#1E90FF", "#00BFFF", "#9370DB", "#6A0DAD", "#A9A9A9",
|
||||||
"#6A5ACD", "#FFA500", "#FF4500", "#20B2AA", "#708090",
|
"#6A5ACD", "#FFA500", "#FF4500", "#20B2AA", "#708090",
|
||||||
],
|
],
|
||||||
|
loading = false,
|
||||||
}) => {
|
}) => {
|
||||||
|
// Show loading state
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div className="w-full h-[380px] flex items-center justify-center bg-gray-100 rounded-xl">
|
||||||
|
<span className="text-gray-500 text-sm">Loading chart...</span>
|
||||||
|
{/* Replace this with a skeleton or spinner if you prefer */}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Guard clause for invalid or incomplete data
|
// Guard clause for invalid or incomplete data
|
||||||
const hasValidData =
|
const hasValidData =
|
||||||
Array.isArray(seriesData) &&
|
Array.isArray(seriesData) &&
|
||||||
@ -48,14 +59,14 @@ const HorizontalBarChart = ({
|
|||||||
distributed: true,
|
distributed: true,
|
||||||
horizontal: true,
|
horizontal: true,
|
||||||
dataLabels: {
|
dataLabels: {
|
||||||
position: "start",
|
position: "center",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
colors,
|
colors,
|
||||||
dataLabels: {
|
dataLabels: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
textAnchor: "start",
|
textAnchor: "center",
|
||||||
style: {
|
style: {
|
||||||
colors: ["#000"], // Black labels
|
colors: ["#000"], // Black labels
|
||||||
},
|
},
|
||||||
@ -108,6 +119,7 @@ HorizontalBarChart.propTypes = {
|
|||||||
seriesData: PropTypes.arrayOf(PropTypes.number),
|
seriesData: PropTypes.arrayOf(PropTypes.number),
|
||||||
categories: PropTypes.arrayOf(PropTypes.string),
|
categories: PropTypes.arrayOf(PropTypes.string),
|
||||||
colors: PropTypes.arrayOf(PropTypes.string),
|
colors: PropTypes.arrayOf(PropTypes.string),
|
||||||
|
loading: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default HorizontalBarChart;
|
export default HorizontalBarChart;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user