Visualizing Data with a Step Curve
Demonstrate the use of a step curve type in an area chart, emphasizing how step curves can more clearly represent discrete changes in data values.
import React from 'react';
import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip } from 'recharts';
Imports necessary components from the Recharts library.
const data = [
{ name: 'Page A', value: 400 },
{ name: 'Page B', value: 300 },
{ name: 'Page C', value: 300 },
{ name: 'Page D', value: 200 },
{ name: 'Page E', value: 278 },
{ name: 'Page F', value: 189 }
];
Defines the data in an array of objects, each representing a point in the step curve.
const StepAreaChart = () => (
<AreaChart width={730} height={250} data={data}
margin={{ top: 10, right: 30, left: 0, bottom: 0 }}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="name" />
<YAxis />
<Tooltip />
<Area type="step" dataKey="value" stroke="#8884d8" fill="#8884d8" />
</AreaChart>
);
Creates an AreaChart component utilizing a step curve for visualizing data. The 'type' prop of the Area component is set to 'step' to achieve the discrete step effect in the visualization.
export default StepAreaChart;
Exports the component for use in other parts of the application.