in this code im using apexcharts to display the data in charts , from api. so i have iconbuttons to change the chart types , so if i change any chart type , it re renders all charts , please provide me solution guys #550
const handleChartTypeChange3 = (type) => {
// Save the current scroll position
// const scrollPosition = scrollRef.current.scrollTop;
// Change the chart type
setChartType3(type);
console.log(type);
// Scroll back to the previous position
// scrollRef.current.scrollTop = scrollPosition;
};
const LineChart = React.memo(({ chartData }) => {
const chartsTextClass = {
color: theme.palette.text.secondary // Change this to your desired text color
};
const options = {
chart: {
background: 'transparent',
// id: 'realtime',
type: 'line'
},
xaxis: {
categories: chartData.map((item) => item.monthNo),
labels: {
style: {
colors: chartsTextClass.color // Change this to your desired text color (black in this case)
}
}
},
yaxis: {
labels: {
style: {
colors: chartsTextClass.color // Change this to your desired text color
}
}
},
colors: [theme.colors.primary.main, theme.colors.warning.main],
theme: {
mode: theme.palette.mode
},
grid: {
strokeDashArray: 5,
borderColor: theme.palette.divider
},
dataLabels: {
enabled: false,
style: {
colors: ['#000000'] // Change this to your desired text color (black in this case)
},
offsetX: 3,
background: 'none'
},
stroke: {
curve: 'smooth' // Use 'smooth' for a smooth curve, remove this line for a straight line
}
// colors: chartData.map((item) => item.graphColor) // Update with the desired color for the line
};
const LineChart4 = React.memo(({ chartData4 }) => {
const chartsTextClass = {
color: theme.palette.text.secondary // Change this to your desired text color
};
const options = {
chart: {
background: 'transparent',
// id: 'realtime',
type: 'line4'
},
xaxis: {
categories: chartData4.map((item) => item.monthNo),
labels: {
style: {
colors: chartsTextClass.color // Change this to your desired text color (black in this case)
}
}
},
colors: [theme.colors.primary.main, theme.colors.warning.main],
theme: {
mode: theme.palette.mode
},
grid: {
strokeDashArray: 5,
borderColor: theme.palette.divider
},
yaxis: {
labels: {
style: {
colors: chartsTextClass.color // Change this to your desired text color
}
}
},
stroke: {
curve: 'smooth' // Use 'smooth' for a smooth curve, remove this line for a straight line
},
dataLabels: {
enabled: false,
style: {
colors: ['#000000'] // Change this to your desired text color (black in this case)
},
offsetX: 3,
background: 'none'
}
// colors: chartData.map((item) => item.graphColor) // Update with the desired color for the line
};
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
import React, { useState, useEffect } from 'react'; import Chart from 'react-apexcharts'; import { Card, Grid, IconButton, Tooltip, TextField, Button, Typography, CardHeader, Box, Autocomplete, styled, useTheme, CircularProgress } from '@mui/material'; import { useTranslation } from 'react-i18next'; // import { HelpOutline } from '@mui/icons-material'; import BarChartIcon from '@mui/icons-material/BarChart'; import TimelineIcon from '@mui/icons-material/Timeline'; import PieChartOutlineIcon from '@mui/icons-material/PieChartOutline'; import 'react-datepicker/dist/react-datepicker.css'; import './Styles.css'; import axios from 'axios';
const ChartsNew = () => { const CardHeaderWrapper = styled(CardHeader)( ({ theme }) => ` position: relative;
);
const [chartType, setChartType] = useState('bar'); const [chartType2, setChartType2] = useState('bar2'); const [chartType3, setChartType3] = useState('bar3'); const [chartType4, setChartType4] = useState('bar4'); const [chartData1, setChartData1] = useState([]); const [chartData2, setChartData2] = useState([]); const [chartData3, setChartData3] = useState([]); const [chartData4, setChartData4] = useState([]); const [siteId, setSiteId] = useState('1'); const [year1, setYear1] = useState('2023'); const [loading, setLoading] = useState(true); const theme = useTheme(); const { t } = useTranslation(); const token = localStorage.getItem('jwtToken');
// const scrollRef = useRef();
const fetchData = async () => { try { const [response1, response2, response3, response4] = await Promise.all([ axios.get('/ReportApi/BudgetVsActualSummary', { headers: { Authorization:
Bearer ${token}
, // Include the token in the header 'Content-Type': 'application/json' // Adjust content type if needed }, params: { yearId: year1, // year2: year2, siteId: siteId || undefined, type: 'kwh' || undefined } }), axios.get('/ReportApi/BudgetVsActualSummary', { headers: { Authorization:Bearer ${token}
, // Include the token in the header 'Content-Type': 'application/json' // Adjust content type if needed }, params: { yearId: year1, // year2: year2, siteId: siteId || undefined, type: 'Inr' || undefined } }), axios.get('/ReportApi/BudgetVsActualSummary', { headers: { Authorization:Bearer ${token}
, // Include the token in the header 'Content-Type': 'application/json' // Adjust content type if needed }, params: { yearId: year1, // year2: year2, siteId: siteId || undefined, type: 'kva' || undefined } }), axios.get('/ReportApi/BudgetVsActualSummary', { headers: { Authorization:Bearer ${token}
, // Include the token in the header 'Content-Type': 'application/json' // Adjust content type if needed }, params: { yearId: year1, // year2: year2, siteId: siteId || undefined, type: 'hvac' || undefined};
useEffect(() => { fetchData(); }, [siteId]);
const handleChartTypeChange = (type) => { setChartType(type); console.log(type); };
const handleChartTypeChange2 = (type) => { setChartType2(type); console.log(type); };
const handleChartTypeChange3 = (type) => { // Save the current scroll position // const scrollPosition = scrollRef.current.scrollTop; // Change the chart type setChartType3(type); console.log(type); // Scroll back to the previous position // scrollRef.current.scrollTop = scrollPosition; };
const handleChartTypeChange4 = (type) => { setChartType4(type); console.log(type); };
const handleYearChange1 = (event, newValue) => { setYear1(newValue ? newValue.value : ''); };
const BarChart = React.memo(({ chartData }) => { const chartsTextClass = { color: theme.palette.text.secondary // Change this to your desired text color }; const options = { chart: { background: 'transparent', height: 375, type: 'bar' }, dataLabels: { enabled: false, style: { colors: ['#000000'] } }, colors: [theme.colors.primary.main, theme.colors.warning.main], theme: { mode: theme.palette.mode }, grid: { strokeDashArray: 5, borderColor: theme.palette.divider }, xaxis: { categories: chartData.map((item) => item.monthNo), labels: { style: { colors: chartsTextClass.color // Change this to your desired text color (black in this case) } } // labels: chartData.map((item) => item.category) }, stroke: { width: null }, yaxis: { labels: { style: { colors: chartsTextClass.color // Change this to your desired text color } } }, plotOptions: { bar: { // horizontal: false, columnWidth: '40%', categorySpacing: 2 // distributed: true, // Enable distributed bars } } };
});
const LineChart = React.memo(({ chartData }) => { const chartsTextClass = { color: theme.palette.text.secondary // Change this to your desired text color }; const options = { chart: { background: 'transparent', // id: 'realtime', type: 'line' }, xaxis: { categories: chartData.map((item) => item.monthNo), labels: { style: { colors: chartsTextClass.color // Change this to your desired text color (black in this case) } } }, yaxis: { labels: { style: { colors: chartsTextClass.color // Change this to your desired text color } } }, colors: [theme.colors.primary.main, theme.colors.warning.main], theme: { mode: theme.palette.mode }, grid: { strokeDashArray: 5, borderColor: theme.palette.divider }, dataLabels: { enabled: false, style: { colors: ['#000000'] // Change this to your desired text color (black in this case) }, offsetX: 3, background: 'none' }, stroke: { curve: 'smooth' // Use 'smooth' for a smooth curve, remove this line for a straight line } // colors: chartData.map((item) => item.graphColor) // Update with the desired color for the line };
});
// * --------------------------------------------------------------------------------
const BarChart2 = React.memo(({ chartData2 }) => { const chartsTextClass = { color: theme.palette.text.secondary // Change this to your desired text color }; const options = { chart: { // id: 'basic-bar', background: 'transparent', type: 'bar2' }, dataLabels: { enabled: false }, stroke: { width: null }, xaxis: { categories: chartData2.map((item) => item.monthNo), // labels: chartData.map((item) => item.category) labels: { style: { colors: chartsTextClass.color // Change this to your desired text color (black in this case) } } }, yaxis: { labels: { style: { colors: chartsTextClass.color // Change this to your desired text color } } }, colors: [theme.colors.primary.main, theme.colors.warning.main], theme: { mode: theme.palette.mode }, grid: { strokeDashArray: 5, borderColor: theme.palette.divider }, plotOptions: { bar: { // horizontal: false, columnWidth: '40%', categorySpacing: 2 // distributed: true, // Enable distributed bars } }
});
const LineChart2 = React.memo(({ chartData2 }) => { const chartsTextClass = { color: theme.palette.text.secondary // Change this to your desired text color }; const options = { chart: { background: 'transparent', // id: 'realtime', type: 'line2' }, xaxis: { categories: chartData2.map((item) => item.monthNo), // labels: chartData.map((item) => item.category) labels: { style: { colors: chartsTextClass.color // Change this to your desired text color (black in this case) } } }, dataLabels: { enabled: false, style: { colors: ['#000000'] // Change this to your desired text color (black in this case) }, offsetX: 3, background: 'none' }, colors: [theme.colors.primary.main, theme.colors.warning.main], theme: { mode: theme.palette.mode }, grid: { strokeDashArray: 5, borderColor: theme.palette.divider }, yaxis: { labels: { style: { colors: chartsTextClass.color // Change this to your desired text color } } }
});
// * --------------------------------------------------------------------------------
const BarChart3 = React.memo(({ chartData3 }) => { const chartsTextClass = { color: theme.palette.text.secondary // Change this to your desired text color }; const options = { chart: { background: 'transparent', // id: 'basic-bar', type: 'bar3' }, stroke: { width: null }, dataLabels: { enabled: false }, xaxis: { categories: chartData3.map((item) => item.monthNo), // labels: chartData.map((item) => item.category) labels: { style: { colors: chartsTextClass.color // Change this to your desired text color (black in this case) } } }, yaxis: { labels: { style: { colors: chartsTextClass.color // Change this to your desired text color } } }, colors: [theme.colors.primary.main, theme.colors.warning.main], theme: { mode: theme.palette.mode }, grid: { strokeDashArray: 5, borderColor: theme.palette.divider }, plotOptions: { bar: { // horizontal: false, columnWidth: '40%', categorySpacing: 2 // distributed: true, // Enable distributed bars } }
});
const LineChart3 = React.memo(({ chartData3 }) => { const chartsTextClass = { color: theme.palette.text.secondary // Change this to your desired text color }; const options = { chart: { background: 'transparent', // id: 'realtime', type: 'line3' },
});
// * --------------------------------------------------------------------------------
const BarChart4 = React.memo(({ chartData4 }) => { const chartsTextClass = { color: theme.palette.text.secondary // Change this to your desired text color }; const options = { chart: { background: 'transparent', // id: 'basic-bar', type: 'bar4' }, dataLabels: { enabled: false }, xaxis: { categories: chartData4.map((item) => item.monthNo), // labels: chartData.map((item) => item.category) labels: { style: { colors: chartsTextClass.color // Change this to your desired text color (black in this case) } } }, colors: [theme.colors.primary.main, theme.colors.warning.main], theme: { mode: theme.palette.mode }, grid: { strokeDashArray: 5, borderColor: theme.palette.divider }, yaxis: { labels: { style: { colors: chartsTextClass.color // Change this to your desired text color } } }, stroke: { width: null }, plotOptions: { bar: { // horizontal: false, columnWidth: '40%', categorySpacing: 2 // distributed: true, // Enable distributed bars } } };
});
const LineChart4 = React.memo(({ chartData4 }) => { const chartsTextClass = { color: theme.palette.text.secondary // Change this to your desired text color }; const options = { chart: { background: 'transparent', // id: 'realtime', type: 'line4' }, xaxis: { categories: chartData4.map((item) => item.monthNo), labels: { style: { colors: chartsTextClass.color // Change this to your desired text color (black in this case) } } }, colors: [theme.colors.primary.main, theme.colors.warning.main], theme: { mode: theme.palette.mode }, grid: { strokeDashArray: 5, borderColor: theme.palette.divider }, yaxis: { labels: { style: { colors: chartsTextClass.color // Change this to your desired text color } } }, stroke: { curve: 'smooth' // Use 'smooth' for a smooth curve, remove this line for a straight line }, dataLabels: { enabled: false, style: { colors: ['#000000'] // Change this to your desired text color (black in this case) }, offsetX: 3, background: 'none' } // colors: chartData.map((item) => item.graphColor) // Update with the desired color for the line };
});
const handleSiteIdChange = (event, newValue) => { setSiteId(newValue ? newValue.value : ''); };
const handleClear = () => { setYear1(''); setSiteId(''); };
const SelectYears1 = [ { label: '2018', value: '2018' }, { label: '2019', value: '2019' }, { label: '2020', value: '2020' }, { label: '2021', value: '2021' }, { label: '2022', value: '2022' }, { label: '2023', value: '2023' }, { label: '2024', value: '2024' }, { label: '2025', value: '2025' }, { label: '2026', value: '2026' }, { label: '2027', value: '2027' }, { label: '2028', value: '2028' }, { label: '2029', value: '2029' }, { label: '2030', value: '2030' }, { label: '2031', value: '2031' }, { label: '2032', value: '2032' } ];
const SelectSites = [ { label: 'Indiqube AMR Tech park', value: '1' }, { label: 'Indiqube Ashford', value: '2' }, { label: 'Indiqube Aura', value: '3' }, { label: 'Indiqube Golf View', value: '4' }, { label: 'Indiqube Ocean', value: '5' }, { label: 'Indiqube Orion', value: '6' }, { label: 'IndiQube Pearl', value: '7' }, { label: 'Indiqube Prime', value: '8' }, { label: 'Indiqube Amar Apex', value: '9' } ];
return (
); };
export default ChartsNew;
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.