Handle widget chart tooltip
This commit is contained in:
parent
4b3f8cc50f
commit
3cf13d0bb6
@ -6,8 +6,16 @@ const HorizontalBarChart = ({
|
|||||||
seriesData = [],
|
seriesData = [],
|
||||||
categories = [],
|
categories = [],
|
||||||
colors = [
|
colors = [
|
||||||
"#1E90FF", "#00BFFF", "#9370DB", "#6A0DAD", "#A9A9A9",
|
"#1E90FF",
|
||||||
"#6A5ACD", "#FFA500", "#FF4500", "#20B2AA", "#708090",
|
"#00BFFF",
|
||||||
|
"#9370DB",
|
||||||
|
"#6A0DAD",
|
||||||
|
"#A9A9A9",
|
||||||
|
"#6A5ACD",
|
||||||
|
"#FFA500",
|
||||||
|
"#FF4500",
|
||||||
|
"#20B2AA",
|
||||||
|
"#708090",
|
||||||
],
|
],
|
||||||
loading = false,
|
loading = false,
|
||||||
}) => {
|
}) => {
|
||||||
@ -31,7 +39,6 @@ const HorizontalBarChart = ({
|
|||||||
if (!hasValidData) {
|
if (!hasValidData) {
|
||||||
return <div className="text-center text-gray-500">No data to display</div>;
|
return <div className="text-center text-gray-500">No data to display</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine seriesData and categories, then sort in descending order
|
// Combine seriesData and categories, then sort in descending order
|
||||||
const combined = seriesData.map((value, index) => ({
|
const combined = seriesData.map((value, index) => ({
|
||||||
value,
|
value,
|
||||||
@ -40,11 +47,13 @@ const HorizontalBarChart = ({
|
|||||||
const sorted = combined.sort((a, b) => b.value - a.value);
|
const sorted = combined.sort((a, b) => b.value - a.value);
|
||||||
|
|
||||||
// Extract sorted values
|
// Extract sorted values
|
||||||
const sortedSeriesData = sorted.map(item => item.value);
|
const sortedSeriesData = sorted.map((item) => item.value);
|
||||||
const sortedCategories = sorted.map(item => item.label);
|
const sortedCategories = sorted.map((item) => item.label);
|
||||||
|
|
||||||
// Replace 0 with 1 for visual purposes, but display "0%" in labels
|
// Replace 0 with 1 for visual purposes, but display "0%" in labels
|
||||||
const adjustedSeriesData = sortedSeriesData.map(val => (val === 0 ? 1 : val));
|
const adjustedSeriesData = sortedSeriesData.map((val) =>
|
||||||
|
val === 0 ? 0.1 : val
|
||||||
|
);
|
||||||
|
|
||||||
// Dynamically adjust chart height if only one data point
|
// Dynamically adjust chart height if only one data point
|
||||||
const chartHeight = seriesData.length === 1 ? 80 : 380;
|
const chartHeight = seriesData.length === 1 ? 80 : 380;
|
||||||
@ -102,11 +111,10 @@ const HorizontalBarChart = ({
|
|||||||
show: true,
|
show: true,
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
theme: "dark",
|
|
||||||
x: { show: true },
|
x: { show: true },
|
||||||
y: {
|
y: {
|
||||||
title: {
|
formatter: function (val) {
|
||||||
formatter: () => "",
|
return (val < 1 ? Math.floor(val) : val) + "%";
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -116,7 +124,7 @@ const HorizontalBarChart = ({
|
|||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<ReactApexChart
|
<ReactApexChart
|
||||||
options={chartOptions}
|
options={chartOptions}
|
||||||
series={[{ data: adjustedSeriesData }]}
|
series={[{ data: adjustedSeriesData, name: "Complete Status" }]}
|
||||||
type="bar"
|
type="bar"
|
||||||
height={chartHeight}
|
height={chartHeight}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user