Skip to main content
Version: 1.2.0

Area Chart

An Area chart is a graphical representation of an asset's historical price action that connects a series of data points with a continuous line. This is the most basic type of chart used in finance and typically only depicts a security's closing prices over time. Here, area charts are developed with react-vis.

Live Editor

Usage

1 . Import AreaChart after installation

import { AreaChart } from "@k2/rv-viz";

2 . Add data or URL to AreaChart component.

<AreaChart data={AreaChartData} />
// or
<AreaChart url="server/api/data" />

Examples

Basic Area Chart: Demo

import { AreaChart } from "@k2/rv-viz";
const data = [
{
curve: "curveMonotoneX",
data: [
{ x: 0, y: 8 },
{ x: 1, y: 9 },
{ x: 2, y: 11 },
{ x: 3, y: 11 },
{ x: 4, y: 13 },
{ x: 5, y: 14 },
{ x: 6, y: 16 },
],
name: "seriesOne",
color: "#85be50",
},
];
function RenderChart() {
return <AreaChart data={data} />;
}

Area With Zoning: Demo

import { AreaChart } from "@k2/rv-viz";
const data = [
{
name: "seriesOne",
color: "#e5be20",
curve: "curveMonotoneX",
data: [
{ x: 0, y: 8 },
{ x: 1, y: 9 },
{ x: 2, y: 11 },
{ x: 3, y: 11 },
{ x: 4, y: 13 },
{ x: 5, y: 14 },
{ x: 6, y: 16 },
],
},
];
const zone = {
axis: "x",
domain: [0, 6],
range: [
{
color: {
name: "series1",
startingColor: "red",
endingColor: "#ffffff",
},
end: 1,
},
{
color: {
name: "series2",
startingColor: "orange",
endingColor: "#ffffff",
},
end: 5,
},
{
color: {
name: "series3",
startingColor: "green",
endingColor: "#ffffff",
},
end: 6,
},
],
};
function RenderChart() {
return <AreaChart data={data} zone={zone} />;
}

Stacked Area Chart: Demo

import { AreaChart } from "@k2/rv-viz";
/**
* @param stroke: for line as top boundary.
* @param curve: for area shape.
**/
const data = [
{
name: "Total TCP Connections",
stroke: "#a575b6",
color: "#a575b6",
opacity: 0.2,
curve: "curveMonotoneX",
data: [
{ x: 0, y: 8 },
{ x: 1, y: 9 },
{ x: 2, y: 11 },
{ x: 3, y: 4 },
{ x: 4, y: 5 },
{ x: 5, y: 8 },
{ x: 6, y: 17 },
],
},
{
name: "Total SSL Sessions",
stroke: "#12aada",
color: "#12aada",
opacity: 0.2,
curve: "curveMonotoneX",
data: [
{ x: 0, y: 8 },
{ x: 1, y: 9 },
{ x: 2, y: 11 },
{ x: 3, y: 4 },
{ x: 4, y: 5 },
{ x: 5, y: 8 },
{ x: 6, y: 17 },
],
},
{
name: "Inspected SSL Sessions",
stroke: "#e79a5a",
opacity: 0.2,
color: "#e79a5a",
curve: "curveMonotoneX",
data: [
{ x: 0, y: 8 },
{ x: 1, y: 9 },
{ x: 2, y: 11 },
{ x: 3, y: 4 },
{ x: 4, y: 5 },
{ x: 5, y: 8 },
{ x: 6, y: 17 },
],
},
];
const xyPlot = {
// For stacking
stackBy: "y",
};
function RenderChart() {
return <AreaChart data={data} xyPlot={xyPlot} />;
}

Click here for more variations of area chart.

Props

Note: External props are mostly derived from react-vis & K2. All external props are linked. You can click highlighted props to get more details from official sites.

PropertyTypeRequiredDefault valueDescription
dataAreaChartData[]YesNoneData for the AreaChart.
xyPlotXYPlotPropsnoNoneInherited from "react-vis"
xAxisboolean | XAxisPropsnotrueEnable or customize XAxis. Inherited from "react-vis".
yAxisboolean |YAxisPropsnotrueEnable or customize YAxis. Inherited from "react-vis".
verticalGridLinesboolean | VerticalGridLinesPropsnotrueEnable or customize VerticalGridLines. Inherited from "react-vis".
horizontalGridLinesboolean | HorizontalGridLinesPropsnotrueEnable or customize HorizontalGridLines. Inherited from "react-vis".
colors"light" | "dark" | GradientColorno"light"Colors of visual in different theme modes
titlestring | JSX.ElementnoNoneTitle of the chart.
zoneZonePropsnoNoneZones of the AreaChart.
animatebooleannotrueEnable the animation.
legendsboolean | LegendsPropsnotrueEnable or customize the legends.
crosshairboolean | CrosshairPropsnotrueEnable or customize the crosshair.
onClick(params: { data: AreaChartData }) => voidnoNoneCallback for AreaChart click.
styleCSSPropertiesnoNoneStyles applied to the root element of chart.
classNamestringnoNoneClass applied to the root element of chart.
classesClasses APInoNoneClasses API of chart.

AreaChart is wrapped with fetchData HoC, to perform data handling tasks, which adds support for some additional props.

Custom Types

AreaChartData

PropertyTypeRequiredDefault valueDescription
namestringYesNoneName of the series.
dataArray<{x: number, y: number, y0?: number}>YesNoneArray of data for the series.
colorstring | numbernoNoneColor for area series.
opacitynumberno1Opacity of the area chart from 0 (transparent) to 1 (opaque).

AreaChartData extends AreaSeries from react-vis

ZoneProps

PropertyTypeRequiredDefault valueDescription
idstringYes""Id of zone
domainnumber[]Yes[0, 0]Domain of zone, should be start and end value of axis
rangeRangeYes[]Array of objects which contains color and ending value of zone
axis"x" | "y"Yes"x"Direction of zone
legendComponentJSX.elementNoNoneStatic legend component for your zone.

Range

type Range = {
color: string | GradientColor,
end: number,
};

CrosshairProps

PropertyTypeRequiredDefault valueDescription
xFormatter(value: number) => string;noNoneFormatter for thhe xValue of crosshair.
yFormatter(value: number) => string;noNoneFormatter for thhe xValue of crosshair.
component(props: ComponentProps) => JSX.Element;noNoneCustom Component for crosshair.
styleCSSPropertiesnoNoneStyles applied to the root element of crosshair.
classesCrosshair Classes APInoNoneClasses Api of crosshair.
classNamestringnoNoneClass applied to the root element of crosshair.

CrosshairProps extends crosshair from react-vis

ComponentProps

PropertyTypeRequiredDefault valueDescription
dataAreaChartData[]YesNoneData for the AreaChart.
pointDataArray<{x: number, y: number}>YesNoneActive x and y points of crosshair position.
activeSeriesData[key: string]: boolean;YesNoneState of active series in legends.

Crosshair Classes

Classes API enables customization and styling of Crosshair elements through their classes.

ClassNameTypeDefault valueDescription
rootstringNoneApplied to root element of crosshair.
xValuestringNoneApplied to xValue of crosshair.
yValuestringNoneApplied to yValue of crosshair.
seriesLabelstringNoneApplied to seriesLabe of crosshair.

Classes

Classes API enables customization and styling of chart elements through their classes.

ClassNameTypeDefault valueDescription
rootstringNoneApplied to root element of chart.
headerstringNoneApplied to header of chart.
titlestringNoneApplied to title of chart.
legendsstringNoneApplied to legends of chart.
chartstringNoneApplied to svg component of chart.
areaSeriesstringNoneApplied to areaSeries of chart.
lineSeriesstringNoneApplied to lineSeries of chart.
xAxisstringNoneApplied to xAxis of chart.
yAxisstringNoneApplied to yAxis of chart.
xyPlotstringNoneApplied to xyPlot of chart.
crosshairstringNoneApplied to root of crosshair.

Please see Class Specificity for correctly defining it.