Reflex Cloud - Fast, secure & scalable hosting. One command to deploy.

Line Chart

A line chart is a type of chart used to show information that changes over time. Line charts are created by plotting a series of several points and connecting them with a straight line.

Simple Example

For a line chart we must define an rx.recharts.line() component for each set of values we wish to plot. Each rx.recharts.line() component has a data_key which clearly states which variable in our data we are tracking. In this simple example we plot pv and uv as separate lines against the name column which we set as the data_key in rx.recharts.x_axis.

Example with Props

Our second example uses exactly the same data as our first example, except now we add some extra features to our line graphs. We add a type_ prop to rx.recharts.line to style the lines differently. In addition, we add an rx.recharts.cartesian_grid to get a grid in the background, an rx.recharts.legend to give us a legend for our graphs and an rx.recharts.graphing_tooltip to add a box with text that appears when you pause the mouse pointer on an element in the graph.

Layout

The layout prop allows you to set the orientation of the graph to be vertical or horizontal. The margin prop defines the spacing around the graph,

Include margins around your graph to ensure proper spacing and enhance readability. By default, provide margins on all sides of the chart to create a visually appealing and functional representation of your data.

Dynamic Data

Chart data can be modified by tying the data prop to a State var. Most other props, such as type_, can be controlled dynamically as well. In the following example the "Munge Data" button can be used to randomly modify the data, and the two select elements change the line type_. Since the data and style is saved in the per-browser-tab State, the changes will not be visible to other visitors.

To learn how to use the sync_id, x_axis_id and y_axis_id props check out the of the area chart documentation, where these props are all described with examples.

API Reference

rx.recharts.LineChart

A Line chart component in Recharts.

PropType | ValuesDefault
data
List
margin
Dict[str, Any]
sync_id
str
sync_method
"index" | "value"
"index"
layout
"vertical" | "horizontal"
"horizontal"
stack_offset
"expand" | "none" | ...
width
Union[str, int]
"100%"
height
Union[str, int]
"100%"

Valid Children

XAxisYAxisReferenceAreaReferenceDotReferenceLineBrushCartesianGridLegendGraphingTooltipLine

rx.recharts.Line

A Line component in Recharts.

PropType | ValuesDefault
type_
"basis" | "basisClosed" | ...
stroke
Union[str, Color]
rx.color("accent", 9)
stroke_width
int
1
dot
Union[Dict, bool]
{"stroke": rx.color("accent", 10), "fill": rx.color("accent", 4)}
active_dot
Union[Dict, bool]
{"stroke": rx.color("accent", 2), "fill": rx.color("accent", 10)}
label
bool
False
hide
bool
False
connect_nulls
bool
unit
Union[str, int]
points
List
stroke_dasharray
str
layout
"vertical" | "horizontal"
data_key
Union[str, int]
x_axis_id
Union[str, int]
0
y_axis_id
Union[str, int]
0
legend_type
"line" | "plainline" | ...
is_animation_active
bool
True
animation_begin
int
0
animation_duration
int
1500
animation_easing
"ease" | "ease-in" | ...
"ease"
name
Union[str, int]

Valid Children

LabelListErrorBar

Event Triggers

See the full list of default event triggers
TriggerDescription
on_animation_start The customized event handler of animation start
on_animation_end The customized event handler of animation end