All files / src/utils/components/charts StackedColumnChart.jsx

71.42% Statements 5/7
16.66% Branches 1/6
33.33% Functions 1/3
71.42% Lines 5/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150            6x 18x 18x   18x                                                                                                                                                                                 18x                                                                                                    
import { getColorPalette } from "@/theme/CustomColors";
import { useTheme } from "@mui/material/styles";
import { Box, CircularProgress } from "@mui/material";
import Chart from "react-apexcharts";
import { EXPORT_ONLY_TOOLBAR } from "./chartExportToolbar";
 
const StackedColumnChart = ({ data, title, categories, loading }) => {
    const theme = useTheme();
    const themeColors = getColorPalette(theme.palette?.presetName);
 
    const options = {
        title: {
            text: title,
            align: "left",
            style: {
                fontSize: "16px",
                fontWeight: "bold",
                color: theme.palette.text.primary,
            },
        },
        grid: {
            borderColor: theme.palette.divider,
            row: {
                colors: ["#f3f3f3", "transparent"],
                opacity: 0.5,
            },
        },
        chart: {
            id: "stacked-column-chart",
            type: "bar",
            stacked: true,
            // EI-3209 — expose the export menu (PNG/SVG/CSV); keep zoom/pan off for
            // a clean UI. Shared with the Data Analytics charts (EI-3067) so the
            // two pages cannot drift apart again.
            toolbar: EXPORT_ONLY_TOOLBAR,
        },
        colors: themeColors,
        plotOptions: {
            bar: {
                horizontal: false,
                borderRadius: 4,
            },
        },
        xaxis: {
            categories: categories,
            labels: {
                style: {
                    colors: theme.palette.text.secondary,
                },
            },
            axisBorder: {
                color: theme.palette.divider,
            },
            axisTicks: {
                color: theme.palette.divider,
            },
            // title: {
            //     text: "X-Axis Label",
            //     style: {
            //         color: theme.palette.primary.main,
            //         fontSize: "14px",
            //         fontWeight: "bold",
            //     },
            // },
        },
        yaxis: {
            labels: {
                style: {
                    colors: theme.palette.text.secondary,
                },
                formatter: (val) => (typeof val === "number" ? parseFloat(val.toFixed(2)) : val),
            },
            // title: {
            //     text: "Y-Axis Label",
            //     style: {
            //         color: theme.palette.primary.main,
            //         fontSize: "14px",
            //         fontWeight: "bold",
            //     },
            // },
        },
        fill: {
            opacity: 1,
            colors: themeColors,
        },
        legend: {
            position: "top",
            labels: {
                colors: theme.palette.text.primary,
            },
        },
        tooltip: {
            theme: theme.palette.mode,
            y: {
                formatter: (val) => (typeof val === "number" ? parseFloat(val.toFixed(2)) : val),
            },
        },
    };
 
    return loading ? (
        <Box display="flex" justifyContent="center" alignItems="center" height={350}>
            <CircularProgress />
        </Box>
    ) : (
        <Chart options={options} series={data} type="bar" height={350} />
    );
};
 
export default StackedColumnChart;
 
//HOW TO USE:
{
    /* <Paper
    id="student-dashboard-graph-my-grades"
    elevation={2}
    sx={{
        width: "100%",
        padding: "2%",
    }}
>
    <StackedColumnChart title="Registered Users" data={series} categories={categories} />
</Paper>;
 
const series = [
    {
        name: "Teachers",
        data: [13, 23, 20, 44, 55, 41, 44, 55, 41, 44, 55, 41],
    },
    {
        name: "Students",
        data: [11, 17, 15, 44, 55, 41, 44, 55, 41, 44, 55, 41],
    },
];
 
const categories = [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December",
]; */
}