Line Chart
The following file represents the data structure that the simulation must output for the graph to be plotted as a line graph. The props for the LineChart component are also shown below is described in the Configuration section.
type LineChartData = {
title: string;
xlabel: string;
ylabel: string;
data: {
x: number[] | number[][]; // either one array of x values (global), or an array of arrays of x values for each line
y: number[][]; // each array is a line [[...], [...], [...]] or single line [...]
labels: string[]; // each label is a line ["label1", "label2", "label3"]
ymin?: number[][]; // same dim as y
ymax?: number[][]; // same dim as y
};
};Basic Examples
Note in these examples we omit the title, xlabel, and ylabel for brevity.
One Line
<LineChart
data={{
x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
y: [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],
labels: ["label1"],
}}
title="1 Line"
xlabel="x"
ylabel="y"
/>Three Lines
<LineChart
data={{
x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
y: [
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20],
[3, 6, 9, 12, 15, 18, 21, 24, 27, 30],
],
labels: ["label1", "label2", "label3"],
}}
title="3 Lines, Same X values"
xlabel="x"
ylabel="y"
/>Contionous Error Bar
<LineChart
data={{
x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
y: [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],
labels: ["label1"],
ymin: [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]],
ymax: [[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]],
}}
title="1 Line"
xlabel="x"
ylabel="y"
/>Configuration
The props for the LineChart extend the LineChartData type, and are as follows:
export interface LineProps extends LineChartData {
cardProps?: CardProps;
divId?: string;
height?: number;
dateTime?: boolean;
fill?: boolean;
chartType?: "webgl" | "svg";
defaultCurveStyle?: "linear" | "step" | "natural";
allowSelectCurveStyle?: boolean;
marker?: "line" | "scatter";
}cardProps- props for theCardcomponent that wraps theLineChartcomponentdivId- the id of the div that wraps theLineChartcomponent (you don't really need to worry about this)height- the height of theLineChartcomponent, in pixels, use this to make the chart bigger or smaller from the default sizefillshades the area under the line (default is false)chartType- the type of chart to use, eitherwebglorsvg(default iswebgl). Usewebglfor large datasets, andsvgwhen you have more than 8 charts on the page.webglis more performant.
dateTime
The dateTime prop allows for conversion of unix timestamp (in ms) x values into human readable date strings. eg.
<LineChart
data={{
x: [
1614556800000, 1614643200000, 1614729600000, 1614816000000, 1614902400000,
],
y: [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],
labels: ["label1"],
}}
title="1 Line"
xlabel="x"
ylabel="y"
dateTime // could also be dateTime={true}
/>defaultCurveStyle
The default curve style prop allows for the default curve style to be set. The default is linear, but can be set to step or natural. eg.
<LineChart
data={{
x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
y: [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],
labels: ["label1"],
}}
title="1 Line"
xlabel="x"
ylabel="y"
defaultCurveStyle="step"
/>allowSelectCurveStyle
The allow select curve style prop allows for the curve style to be selected by the user via a dropdown in the top right. The default is false, but can be set to true. eg.
<LineChart
data={{
x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
y: [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],
labels: ["label1"],
}}
title="1 Line"
xlabel="x"
ylabel="y"
allowSelectCurveStyle
/>marker
The marker prop allows for the marker to be set. The default is line, but can be set to scatter. eg.
<LineChart
data={{
x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
y: [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],
labels: ["label1"],
}}
title="1 Line"
xlabel="x"
ylabel="y"
marker="scatter"
/>