
"use client";
import React from 'react'
import { useTheme } from "@mui/material";
import { LineChart, lineElementClasses } from '@mui/x-charts/LineChart';
const BCrumb = [
{
to: '/',
title: 'Home',
},
{
title: 'SimpleAreaChart ',
},
];
export default function SimpleAreaChart() {
const monthlyProfits = [4000, 3000, 2000, 2780, 1890, 2390, 3490];
const xLabels = ["January", "February", "March", "April", "May", "June", "July"];
const theme = useTheme();
const primary = theme.palette.primary.main;
return (
<LineChart
width={500}
height={300}
series={[{ data: monthlyProfits, label: 'Profits', area: true, showMark: false, color: primary }]}
xAxis={[{ scaleType: 'point', data: xLabels }]}
sx={{
[`& .${lineElementClasses.root}`]: {
display: 'none',
},
}}
/>
);
}
"use client";
import * as React from 'react';
import { LineChart, lineElementClasses } from '@mui/x-charts/LineChart';
import { useTheme } from "@mui/material";
const BCrumb = [
{
to: '/',
title: 'Home',
},
{
title: 'StackedAreaChart ',
},
];
export default function StackedAreaChart() {
const monthlyProfits = [4000, 3000, 2000, 2780, 1890, 2390, 3490];
const monthlyRevenue = [2400, 1398, 9800, 3908, 4800, 3800, 4300];
const monthlyExpenses = [2400, 2210, 0, 2000, 2181, 2500, 2100];
const xLabels = ["January", "February", "March", "April", "May", "June", "July"];
const theme = useTheme();
const primary = theme.palette.primary.main;
const secondary = theme.palette.secondary.main;
const expDatacolor = theme.palette.error.main;
return (
<LineChart
width={500}
height={300}
series={[
{ data: monthlyRevenue, label: 'Revenue', area: true, stack: 'total', showMark: false, color: primary },
{ data: monthlyProfits, label: 'Profits', area: true, stack: 'total', showMark: false, color: secondary },
{
data: monthlyExpenses,
label: 'Expenses',
area: true,
stack: 'total',
showMark: false,
color: expDatacolor
},
]}
xAxis={[{ scaleType: 'point', data: xLabels }]}
sx={{
[`& .${lineElementClasses.root}`]: {
display: 'none',
},
}}
/>
);
}
"use client";
import * as React from 'react';
import { LineChart, lineElementClasses } from '@mui/x-charts/LineChart';
import { useTheme } from "@mui/material";
const BCrumb = [
{
to: '/',
title: 'Home',
},
{
title: 'TinyAreaChart ',
},
];
export default function TinyAreaChart() {
const uData = [4000, 3000, 2000, 2780, 1890, 2390, 3490];
const xLabels = [
' A',
' B',
' C',
' D',
' E',
' F',
' G',
];
const theme = useTheme();
const primary = theme.palette.primary.main;
return (
<ChartContainer
width={500}
height={300}
series={[
{
data: uData,
type: 'line',
label: 'uv',
area: true,
stack: 'total',
color: primary
},
]}
xAxis={[{ scaleType: 'point', data: xLabels }]}
>
<AreaPlot />
</ChartContainer>
);
}
"use client";
import * as React from 'react';
import { LineChart } from '@mui/x-charts/LineChart';
import { useTheme } from '@mui/material';
const BCrumb = [
{
to: '/',
title: 'Home',
},
{
title: 'PercentAreaChart ',
},
];
const time = [
new Date(2015, 1, 0),
new Date(2015, 2, 0),
new Date(2015, 3, 0),
new Date(2015, 4, 0),
new Date(2015, 5, 0),
new Date(2015, 6, 0),
new Date(2015, 7, 0),
];
const a = [4000, 3000, 2000, 2780, 1890, 2390, 3490];
const b = [2400, 1398, 9800, 3908, 4800, 3800, 4300];
const c = [2400, 2210, 2290, 2000, 2181, 2500, 2100];
const getPercents = (array) =>
array.map((v, index) => (100 * v) / (a[index] + b[index] + c[index]));
export default function PercentAreaChart() {
const theme = useTheme();
const primary = theme.palette.primary.main;
const secondary = theme.palette.secondary.main;
const amtDatacolor = theme.palette.error.main;
return (
<LineChart
width={500}
height={300}
series={[
{
data: getPercents(a),
type: 'line',
label: 'Revenue',
area: true,
stack: 'total',
showMark: false,
color: primary
},
{
data: getPercents(b),
type: 'line',
label: 'Profits',
area: true,
stack: 'total',
showMark: false,
color: secondary
},
{
data: getPercents(c),
type: 'line',
label: 'Expenses',
area: true,
stack: 'total',
showMark: false,
color: amtDatacolor
},
]}
xAxis={[
{
scaleType: 'time',
data: time,
min: time[0].getTime(),
max: time[time.length - 1].getTime(),
},
]}
/>
);
}
'use client'
import * as React from 'react';
import Stack from '@mui/material/Stack';
import { LineChart } from '@mui/x-charts/LineChart';
import { useTheme } from '@mui/material';
const BCrumb = [
{
to: '/',
title: 'Home',
},
{
title: 'AreaChartConnectNulls ',
},
];
export default function AreaChartConnectNulls() {
const data = [4000, 3000, 2000, null, 1890, 2390, 3490];
const xData = ["January", "February", "March", "April", "May", "June", "July"];
const theme = useTheme();
const primary = theme.palette.primary.main;
return (
<Stack sx={{ width: '100%' }}>
<LineChart
xAxis={[{ data: xData, scaleType: 'point' }]}
series={[{ data, showMark: false, area: true, color: primary }]}
height={200}
margin={{ top: 10, bottom: 20 }}
/>
<LineChart
xAxis={[{ data: xData, scaleType: 'point' }]}
series={[{ data, showMark: false, area: true, connectNulls: true, color: primary}]}
height={200}
margin={{ top: 10, bottom: 20 }}
/>
</Stack>
);
}
'use client'
import * as React from 'react';
import { ScaleLinear } from 'd3-scale';
import { green, red } from '@mui/material/colors';
import Stack from '@mui/material/Stack';
import { useYScale, useDrawingArea } from '@mui/x-charts/hooks';
import { LineChart, areaElementClasses } from '@mui/x-charts/LineChart';
import { useTheme } from '@mui/material';
const BCrumb = [
{
to: '/',
title: 'Home',
},
{
title: 'AreaChartFillByValue ',
},
];
function ColorSwich({ threshold, color1, color2, id }) {
const { top, height, bottom } = useDrawingArea();
const svgHeight = top + bottom + height;
const scale = useYScale(); // You can provide the axis Id if you have multiple ones
const y0 = scale(threshold); // The coordinate of of the origine
const off = y0 !== undefined ? y0 / svgHeight : 0;
return (
<defs>
<linearGradient
id={id}
x1="0"
x2="0"
y1="0"
y2={`${svgHeight}px`}
gradientUnits="userSpaceOnUse"
>
<stop offset={off} stopColor={color1} stopOpacity={1} />
<stop offset={off} stopColor={color2} stopOpacity={1} />
</linearGradient>
</defs >
);
}
export default function AreaChartFillByValue() {
const data = [4000, 3000, -1000, 500, -2100, -250, 3490];
const xData = ["January", "February", "March", "April", "May", "June", "July"];
const theme = useTheme();
const primary = theme.palette.primary.main;
const secondary = theme.palette.secondary.main;
const amtDatacolor = theme.palette.error.main;
return (
<Stack direction="column" width="100%" spacing={1}>
<LineChart
xAxis={[{ data: xData, scaleType: 'point' }]}
yAxis={[{ min: -3000, max: 4000 }]}
series={[{ data, showMark: false, area: true }]}
height={200}
margin={{ top: 20, bottom: 30, left: 75 }}
sx={{
[`& .${areaElementClasses.root}`]: { // Dynamic class name
fill: 'url(#swich-color-id-1)',
},
}}
>
<ColorSwich
color1={primary}
color2={amtDatacolor}
threshold={0}
id="swich-color-id-1"
/>
<rect x={0} y={0} width={5} height="100%" fill="url(#swich-color-id-1)" />
</LineChart>
<LineChart
xAxis={[{ data: xData, scaleType: 'point' }]}
yAxis={[{ min: -3000, max: 4000 }]}
series={[{ data, showMark: false, area: true }]}
height={200}
margin={{ top: 20, bottom: 30, left: 75 }}
sx={{
[`& .${areaElementClasses.root}`]: {
fill: 'url(#swich-color-id-2)',
},
}}
>
<ColorPalette id="swich-color-id-2" />
<rect x={0} y={0} width={5} height="100%" fill="url(#swich-color-id-2)" />
</LineChart>
</Stack >
);
}
function ColorPalette({ id }) {
const { top, height, bottom } = useDrawingArea();
const svgHeight = top + bottom + height;
const scale = useYScale() // You can provide the axis Id if you have multiple ones
return (
<defs>
<linearGradient
id={id}
x1="0"
x2="0"
y1="0"
y2={`${svgHeight}px`}
gradientUnits="userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
>
<stop
offset={scale(5000) / svgHeight}
stopColor={green[400]}
stopOpacity={1}
/>
<stop
offset={scale(4000) / svgHeight}
stopColor={green[400]}
stopOpacity={1}
/>
<stop
offset={scale(4000) / svgHeight}
stopColor={green[300]}
stopOpacity={1}
/>
<stop
offset={scale(3000) / svgHeight}
stopColor={green[300]}
stopOpacity={1}
/>
<stop
offset={scale(3000) / svgHeight}
stopColor={green[200]}
stopOpacity={1}
/>
<stop
offset={scale(2000) / svgHeight}
stopColor={green[200]}
stopOpacity={1}
/>
<stop
offset={scale(2000) / svgHeight}
stopColor={green[100]}
stopOpacity={1}
/>
<stop
offset={scale(1000) / svgHeight}
stopColor={green[100]}
stopOpacity={1}
/>
<stop
offset={scale(1000) / svgHeight}
stopColor={green[50]}
stopOpacity={1}
/>
<stop offset={scale(0) / svgHeight} stopColor={green[50]} stopOpacity={1} />
<stop offset={scale(0) / svgHeight} stopColor={red[100]} stopOpacity={1} />
<stop
offset={scale(-1000) / svgHeight}
stopColor={red[100]}
stopOpacity={1}
/>
<stop
offset={scale(-1000) / svgHeight}
stopColor={red[200]}
stopOpacity={1}
/>
<stop
offset={scale(-2000) / svgHeight}
stopColor={red[200]}
stopOpacity={1}
/>
<stop
offset={scale(-3000) / svgHeight}
stopColor={red[300]}
stopOpacity={1}
/>
</linearGradient>
</defs>
);
}