Skip to main content
Version: 1.1.0

Line Chart

A line 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. So here the line chart is developed with react-vis.

Live Editor

Usage

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

2 . Add data or URL to LineChart component.

<LineChart data={LineChartData} />
// or
<LineChart url="server/api/data" />

Examples

LineChart With Multiple styles: Demo

import { LineChart } from "@k2/rv-viz";
const data = [
{
name: "value 1",
strokeWidth: 3,
curve: "curveMonotoneX",
color: "#e5be20",
data: [
{ x: 1593003889612, y: 0 },
{ x: 1593003829612, y: 5 },
{ x: 1593003769612, y: 10 },
{ x: 1593003709612, y: 20 },
{ x: 1593003649612, y: 3 },
{ x: 1593003589612, y: 18 },
{ x: 1593003529612, y: 11 },
],
},
{
name: "value 2",
strokeWidth: 3,
curve: "curveMonotoneX",
strokeDasharray: "15 4",
color: "#688bbf",
data: [
{ x: 1593003889612, y: 7 },
{ x: 1593003829612, y: 3 },
{ x: 1593003769612, y: 1 },
{ x: 1593003709612, y: 2 },
{ x: 1593003649612, y: 9 },
{ x: 1593003589612, y: 11 },
{ x: 1593003529612, y: 7 },
],
},
];
function RenderChart() {
return <LineChart data={data} />;
}

LineChart With Spline: Demo

import { LineChart } from "@k2/rv-viz";
const data = [
{
name: "value 1",
color: "#e5be20",
strokeWidth: 3,
curve: "curveMonotoneX",
data: [
{ x: 1593003889612, y: 15 },
{ x: 1593003829612, y: 22 },
{ x: 1593003769612, y: 5 },
{ x: 1593003709612, y: 12 },
{ x: 1593003649612, y: 10 },
{ x: 1593003589612, y: 0 },
{ x: 1593003529612, y: 12 },
],
},
{
name: "value 2",
color: "#688bbf",
strokeWidth: 3,
curve: "curveMonotoneX",
data: [
{ x: 1593003889612, y: 14 },
{ x: 1593003829612, y: 12 },
{ x: 1593003769612, y: 20 },
{ x: 1593003709612, y: 13 },
{ x: 1593003649612, y: 12 },
{ x: 1593003589612, y: 13 },
{ x: 1593003529612, y: 0 },
],
},
];
function RenderChart() {
return <LineChart data={data} />;
}

LineChart With Pointed Arc: Demo

import { LineChart } from "@k2/rv-viz";
const data = [
{
name: "Apps Open",
color: "#6ab04c"
data: [
{ x: 1593003889612, y: 7},
{ x: 1593003829612, y: 3},
{ x: 1593003769612, y: 1},
{ x: 1593003709612, y: 2},
{ x: 1593003649612, y: 9},
{ x: 1593003589612, y: 11},
{ x: 1593003529612, y: 7},
],
},
];
function RenderChart() {
return <LineChart data={data} />;
}

Click here for more variations of line 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
dataLineChartData[]YesNoneData for the LineChart.
xyPlotXYPlotPropsnoNoneInherited from "react-vis"
xAxisboolean | XAxisPropsnotrueEnable or customize XAxis. Inherited from "react-vis".
yAxisboolean | YAxisPropsnotrueEnable or customize YAxis. Inherited from "react-vis".
verticalGridLinesboolean | VerticalGridLinesPropsnofalseEnable or customize VerticalGridLines. Inherited from "react-vis".
horizontalGridLinesboolean | HorizontalGridLinesPropsnofalseEnable 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.
animatebooleannotrueEnable the animation.
legendsboolean | LegendsPropsnotrueEnable or customize the legends.
crosshairboolean | CrosshairPropsnotrueEnable or customize the crosshair.
onClick(params: { data: LineChartData }) => voidnoNoneCallback for LineChart click.
styleCSSPropertiesnoNoneStyles applied to the root element of chart.
classNamestringnoNoneClass applied to the root element of chart.
classesClasses APInoNoneClasses API of chart.

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

Custom Types

LineChartData

PropertyTypeRequiredDefault valueDescription
namestringYesNoneName of the series.
sizestring | numberno5The size of each of the marks.
dataArray<{ x: string | number | date, y: string | number | date }>YesNoneArray of data for the series.
colorstring | numbernoNoneColor for line series.
opacitynumberno1Opacity of the line chart from 0 (transparent) to 1 (opaque).

LineChartData extends LineSeries and LineMarkSeries from react-vis

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.
classNamestringnoNoneClass applied to the root element of crosshair.
classesCrosshair Classes APInoNoneClasses Api of crosshair.

CrosshairProps extends crosshair from react-vis

ComponentProps

PropertyTypeRequiredDefault valueDescription
dataLineChartData[]YesNoneData for the LineChart.
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.
lineSeriesstringNoneApplied to lineSeries of chart.
lineMarkSeriesstringNoneApplied to lineMarkSeries of chart.
xAxisstringNoneApplied to xAxis of chart.
yAxisstringNoneApplied to yAxis of chart.
xyPlotstringNoneApplied to xyPlot of chart.
crosshairstringNoneApplied to the crosshair of the chart.

Please see Class Specificity for correctly defining it.