For AI agents: the complete documentation index is at llms.txt. Markdown versions are available by appending .md or sending Accept: text/markdown.
Reflex Logo
Docs Logo
Library

/

Graphing

/

Charts

/

Linechart

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.

Expand

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.

Expand

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.

Props

PropTypeDescription
width
Union[int, str]

The width of chart container. String or Integer.

height
Union[int, str]

The height of chart container.

data
Sequence

The source data, in which each element is an object.

margin
Dict[str, Any]

The sizes of whitespace around the chart, i.e. {"top": 50, "right": 30, "left": 20, "bottom": 5}.

sync_id
str

If any two categorical charts(rx.line_chart, rx.area_chart, rx.bar_chart, rx.composed_chart) have the same sync_id, these two charts can sync the position GraphingTooltip, and the start_index, end_index of Brush.

sync_method
"index""value"

When sync_id is provided, allows customisation of how the charts will synchronize GraphingTooltips and brushes. Using 'index' (default setting), other charts will reuse current datum's index within the data array. In cases where data does not have the same length, this might yield unexpected results. In that case use 'value' which will try to match other charts values, or a fully custom function which will receive tick, data as argument and should return an index. 'index' | 'value' | function.

layout
"vertical""horizontal"

The layout of area in the chart. 'horizontal' | 'vertical'.

stack_offset
"expand""none""wiggle""silhouette"

The type of offset function used to generate the lower and upper values in the series array. The four types are built-in offsets in d3-shape. 'expand' | 'none' | 'wiggle' | 'silhouette'.

Valid Children

XAxisYAxisReferenceAreaReferenceDotReferenceLineBrushCartesianGridLegendGraphingTooltipLineDefs

rx.recharts.Line

A Line component in Recharts.

Props

PropTypeDescription
layout
"vertical""horizontal"

The layout of bar in the chart, usually inherited from parent. 'horizontal' | 'vertical'.

data_key
Union[int, str]

The key of a group of data which should be unique in an area chart.

x_axis_id
Union[int, str]

The id of x-axis which is corresponding to the data.

y_axis_id
Union[int, str]

The id of y-axis which is corresponding to the data.

legend_type
"circle""cross""diamond""line""plainline""rect""square""star""triangle""wye""none"

The type of icon in legend. If set to 'none', no legend item will be rendered. 'line' | 'plainline' | 'square' | 'rect'| 'circle' | 'cross' | 'diamond' | 'star' | 'triangle' | 'wye' | 'none' optional.

label
Union[dict, bool]

If false set, labels will not be drawn. If true set, labels will be drawn which have the props calculated internally.

is_animation_active
bool

If set false, animation of bar will be disabled.

animation_begin
int

Specifies when the animation should begin, the unit of this option is ms.

animation_duration
int

Specifies the duration of animation, the unit of this option is ms.

animation_easing
"ease""ease-in""ease-out""ease-in-out""linear"

The type of easing function.

unit
Union[int, str]

The unit of data. This option will be used in tooltip.

name
Union[int, str]

The name of data. This option will be used in tooltip and legend to represent the component. If no value was set to this option, the value of dataKey will be used alternatively.

type_
"basis""basisClosed""basisOpen""bumpX""bumpY""bump""linear""linearClosed""natural""monotoneX""monotoneY""monotone""step""stepBefore""stepAfter"

The interpolation type of line. And customized interpolation function can be set to type. It's the same as type in Area.

stroke
Union[str, Color]

The color of the line stroke.

stroke_width
Union[str, int, float]

The width of the line stroke.

dot
Union[dict, bool]

The dot is shown when mouse enter a line chart and this chart has tooltip. If false set, no active dot will not be drawn. If true set, active dot will be drawn which have the props calculated internally.

active_dot
Union[dict, bool]

The dot is shown when user enter an area chart and this chart has tooltip. If false set, no active dot will not be drawn. If true set, active dot will be drawn which have the props calculated internally.

hide
bool

Hides the line when true, useful when toggling visibility state via legend.

connect_nulls
bool

Whether to connect a graph line across null points.

points
Sequence

The coordinates of all the points in the line, usually calculated internally.

stroke_dasharray
str

The pattern of dashes and gaps used to paint the line.

Valid Children

LabelListErrorBar

Event Triggers

See the full list of default event triggers
TriggerDescription
on_animation_startThe customized event handler of animation start.
on_animation_endThe customized event handler of animation end.
Built with Reflex