I have dummy data that save in React state.
If I change state the chart also change . It’s ok.
The problem how to drill my data?
The stackedPrimaryXAxis object’s one attribute easy to change.
** But My questions:**
** 1. But stackedCustomSeries background property?**
** 2. But stackedChartData x and y property?**
export const stackedChartData = [
[
{ x: 'Jan', y: 111.1 },
{ x: 'Feb', y: 127.3 },
{ x: 'Mar', y: 143.4 },
{ x: 'Apr', y: 159.9 },
{ x: 'May', y: 159.9 },
{ x: 'Jun', y: 159.9 },
{ x: 'July', y: 159.9 },
],
[
{ x: 'Jan', y: 111.1 },
{ x: 'Feb', y: 127.3 },
{ x: 'Mar', y: 143.4 },
{ x: 'Apr', y: 159.9 },
{ x: 'May', y: 159.9 },
{ x: 'Jun', y: 159.9 },
{ x: 'July', y: 159.9 },
],
];
export const stackedCustomSeries = [
{ dataSource: stackedChartData[0],
xName: 'x',
yName: 'y',
name: 'Budget',
type: 'StackingColumn',
background: 'blue',
},
{ dataSource: stackedChartData[1],
xName: 'x',
yName: 'y',
name: 'Expense',
type: 'StackingColumn',
background: 'red',
},
];
export const stackedPrimaryXAxis = {
minorGridLines: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 },
interval: 1,
lineStyle: { width: 0 },
labelIntersectAction: 'Rotate45',
valueType: 'Category',
};
export const stackedPrimaryYAxis = {
lineStyle: { width: 0 },
minimum: 100,
maximum: 400,
interval: 100,
majorTickLines: { width: 0 },
majorGridLines: { width: 1 },
minorGridLines: { width: 1 },
minorTickLines: { width: 0 },
labelFormat: '{value}',
}
FreeCodeCamp.js
import React, { useState } from "react";
import {
stackedCustomSeries,
stackedPrimaryXAxis,
stackedPrimaryYAxis,
} from "../../data/dummy";
const FreeCodeCamp = ({ height, width }) => {
const [customSeries, setCustomSeries] = useState(stackedCustomSeries);
const [xaxis, setXaxis] = useState(stackedPrimaryXAxis);
const [yaxis, setYaxis] = useState(stackedPrimaryYAxis);
const handleClick = () => {
setXaxis({ ...xaxis, majorGridLines: { width: 0 } });
setCustomSeries((prevCustomSeries) => {
//missing part...
return prevCustomSeries;
});
};
const handleClick2 = () => {
setXaxis({ ...xaxis, majorGridLines: { width: 1 } });
};
return (
<>
<h2>MyComponent</h2>
<div className="m-5">
<button type="button" onClick={handleClick2}>
ChangeButton
</button>
<div className="mt-3">
<button type="button" onClick={handleClick}>
ChangeButton 2
</button>
</div>
</div>
</>
);
};
export default FreeCodeCamp;