Changed chart's color by theme

This commit is contained in:
Takeshi Kimata
2024-05-08 23:08:46 +09:00
parent 344bd78b79
commit fe537c93aa
6 changed files with 93 additions and 11 deletions

View File

@@ -8,11 +8,13 @@ const Chart = dynamic(() => import("react-apexcharts"), { ssr: false });
type Props = {
progressSeries: ProgressSeriesType[];
progressCategories: string[];
theme: string;
};
export default function TestProgressBarChart({
progressSeries,
progressCategories,
theme,
}: Props) {
const [chartData, setChartData] = useState({
series: [],
@@ -25,6 +27,16 @@ export default function TestProgressBarChart({
useEffect(() => {
const updateChartDate = () => {
if (progressSeries) {
const legendsLabelColors = testRunCaseStatus.map((itr) => {
if (theme === "light") {
return "black";
} else {
return "white";
}
});
const xaxisLabelColor = theme === "light" ? "black" : "white";
setChartData({
series: progressSeries,
options: {
@@ -36,6 +48,9 @@ export default function TestProgressBarChart({
},
legend: {
position: "right",
labels: {
colors: legendsLabelColors,
},
},
colors: testRunCaseStatus.map((itr) => {
return itr.chartColor;
@@ -43,6 +58,14 @@ export default function TestProgressBarChart({
xaxis: {
type: "datetime",
categories: progressCategories,
labels: {
style: {
colors: xaxisLabelColor,
},
},
},
tooltip: {
theme: theme,
},
},
});
@@ -50,7 +73,7 @@ export default function TestProgressBarChart({
};
updateChartDate();
}, [progressSeries, progressCategories]);
}, [progressSeries, progressCategories, theme]);
return (
<Chart