Reflex Logo

Intro

Gallery

Hosting

Components

New

Learn

Components

API Reference

Onboarding

Library

/

Graphing

/

Scatterchart

A scatter chart always has two value axes to show one set of numerical data along a horizontal (value) axis and another set of numerical values along a vertical (value) axis. The chart displays points at the intersection of an x and y numerical value, combining these values into single data points.

For a scatter chart we must define an rx.recharts.scatter() component for each set of values we wish to plot. Each rx.recharts.scatter() component has a data prop which clearly states which data source we plot. We also must define rx.recharts.x_axis() and rx.recharts.y_axis() so that the graph knows what data to plot on each axis.

rx.recharts.scatter_chart(
    rx.recharts.scatter(
        data=data01,
        fill="#8884d8",
    ),
    rx.recharts.x_axis(data_key="x", type_="number"),
    rx.recharts.y_axis(data_key="y"),
)

We can also add two scatters on one chart by using two rx.recharts.scatter() components, and we can define an rx.recharts.z_axis() which represents a third column of data and is represented by the size of the dots in the scatter plot.

rx.recharts.scatter_chart(
    rx.recharts.scatter(
        data=data01, fill="#8884d8", name="A"
    ),
    rx.recharts.scatter(
        data=data02, fill="#82ca9d", name="B"
    ),
    rx.recharts.cartesian_grid(stroke_dasharray="3 3"),
    rx.recharts.x_axis(data_key="x", type_="number"),
    rx.recharts.y_axis(data_key="y"),
    rx.recharts.z_axis(
        data_key="z", range=[60, 400], name="score"
    ),
    rx.recharts.legend(),
    rx.recharts.graphing_tooltip(),
)

Chart data tied to a State var causes the chart to automatically update when the state changes, providing a nice way to visualize data in response to user interface elements. View the "Data" tab to see the substate driving this calculation of iterations in the Collatz Conjecture for a given starting number. Enter a starting number in the box below the chart to recalculate.

def index():
    return rx.vstack(
        rx.recharts.scatter_chart(
            rx.recharts.scatter(
                data=ScatterChartState.data,
                fill="#8884d8",
            ),
            rx.recharts.x_axis(
                data_key="x", type_="number"
            ),
            rx.recharts.y_axis(
                data_key="y", type_="number"
            ),
        ),
        rx.form.root(
            rx.input(
                placeholder="Enter a number", id="start"
            ),
            rx.button("Compute", type="submit"),
            on_submit=ScatterChartState.compute_collatz,
        ),
        width="100%",
        height="15em",
        on_mount=ScatterChartState.compute_collatz(
            {"start": "15"}
        ),
    )
def index():
    return rx.vstack(
        rx.recharts.scatter_chart(
            rx.recharts.scatter(
                data=ScatterChartState.data,
                fill="#8884d8",
            ),
            rx.recharts.x_axis(
                data_key="x", type_="number"
            ),
            rx.recharts.y_axis(
                data_key="y", type_="number"
            ),
        ),
        rx.form.root(
            rx.input(
                placeholder="Enter a number", id="start"
            ),
            rx.button("Compute", type="submit"),
            on_submit=ScatterChartState.compute_collatz,
        ),
        width="100%",
        height="15em",
        on_mount=ScatterChartState.compute_collatz(
            {"start": "15"}
        ),
    )

A Scatter chart component in Recharts.

PropTypeDescriptionValues
dataList

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

sync_idstr

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_methodLiteral

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

widthUnion

The width of chart container. String or Integer

heightUnion

The height of chart container.

layoutLiteral

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

marginDict

The sizes of whitespace around the chart.

stack_offsetLiteral

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

  • XAxis
  • YAxis
  • ZAxis
  • ReferenceArea
  • ReferenceDot
  • ReferenceLine
  • Brush
  • CartesianGrid
  • Legend
  • GraphingTooltip
  • Scatter

A Scatter component in Recharts.

PropTypeDescriptionValues
dataList

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

z_axis_idstr

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

linebool

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

shapeLiteral

If a string set, specified symbol will be used to show scatter item. 'circle' | 'cross' | 'diamond' | 'square' | 'star' | 'triangle' | 'wye'

line_typeLiteral

If 'joint' set, line will generated by just jointing all the points. If 'fitting' set, line will be generated by fitting algorithm. 'joint' | 'fitting'

fillstr

The fill

nameUnion

the name

layoutLiteral

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

data_keyUnion

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

x_axis_idUnion

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

y_axis_idUnion

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

Valid Children

  • LabelList
  • ErrorBar
← ReferenceTooltip →

Did you find this useful?

HomeGalleryChangelogIntroductionHosting