Expand description
Welcome to Chartistry! This crate provides a flexible way to build charts in Leptos.
All charts are built using the Chart fn. If you understand this function, you understand this library.
§Examples
- See the demo for Chartistry in action.
- There is also an large, assorted list of examples available.
Below is an example chart:
use leptos::prelude::*;
use leptos_chartistry::*;
let data: Signal<Vec<MyData>> = load_data(/* pull data from a resource */);
view! {
<Chart
// Sets the width and height
aspect_ratio=AspectRatio::from_outer_ratio(600.0, 300.0)
// Decorate our chart
top=RotatedLabel::middle("My garden")
left=TickLabels::aligned_floats()
right=Legend::end()
bottom=TickLabels::timestamps()
inner=[
AxisMarker::left_edge().into_inner(),
AxisMarker::bottom_edge().into_inner(),
XGridLine::default().into_inner(),
YGridLine::default().into_inner(),
XGuideLine::over_data().into_inner(),
YGuideLine::over_mouse().into_inner(),
]
tooltip=Tooltip::left_cursor()
// Describe the data
series=Series::new(|data: &MyData| data.x)
.line(Line::new(|data: &MyData| data.y1).with_name("butterflies"))
.line(Line::new(|data: &MyData| data.y2).with_name("dragonflies"))
data=data
/>
}Re-exports§
Structs§
- Aligned
Floats - Generates f64 ticks. Aligned to nice values (powers of 10).
- Aspect
Ratio - Calculates the width and height of a chart.
- Axis
Marker - Builds an axis marker. This marks a boundary (e.g., zero or the chart edge) around the inner chart area.
- Bar
- Draws a bar on the chart.
- Colour
- A colour in RGB format.
- Colour
Scheme - A colour scheme with at least one colour.
- Inset
Legend - Builds an inset legend for the chart series. Differs from Legend by being placed inside the chart area.
- Legend
- Builds a legend for the chart series. Orientated along the axis of its placed edge. Drawn in HTML.
- Line
- Draws a line on the chart.
- Marker
- Describes a line point marker.
- Padding
- Represents padding around the edges of a component.
- Rotated
Label - Builds a rotated label to match the orientation of the axis it’s placed on.
- Series
- Describes how to render a series of data. A series is a collection of lines, bars, etc. that share the same X and Y axes.
- Stack
- Draws a stack of lines on top of each other.
- Tick
Labels - Builds tick labels for an axis.
- Timestamps
- Generates timestamp ticks from a set of periods. Aligned to nice values (earlier periods).
- Tooltip
- Builds a mouse tooltip that shows X and Y values for the nearest data. Drawn in HTML as an overlay.
- XGrid
Line - Builds a tick-aligned grid line across the inner chart area.
- XGuide
Line - Builds a mouse guide line. Aligned over the mouse position or nearest data.
- YGrid
Line - Builds a tick-aligned grid line across the inner chart area.
- YGuide
Line - Builds a mouse guide line. Aligned over the mouse position or nearest data.
Enums§
- Align
Over - Align over mouse or nearest data.
- Anchor
- Label placement on the main-axis of a component. An edge layout’s main-axis runs parallel to its given edge. Similar to SVG’s text-anchor or CSS’s justify-content.
- Axis
Placement - Placement of an axis marker around the inner chart area.
- BarPlacement
- The location of where the bar extends from.
- Edge
- Identifies a rectangle edge.
- Edge
Layout - All possible layout options for an edge of a Chart. See IntoEdge for details.
- Inner
Layout - Inner layout options for a Chart. See IntoInner for details.
- Interpolation
- Line interpolation. This is used to determine how to draw the line between points.
- Marker
Shape - Shape of a line marker.
- Period
- Available periods for timestamp tick generation.
- Step
- Step interpolation only uses horizontal and vertical lines to connect two points. We have a choice of where to put the “corner” of the step.
- Tooltip
Placement - Where the tooltip is place when shown.
- Tooltip
Sort By - How the tooltip Y value table is sorted.
Constants§
- AXIS_
MARKER_ COLOUR - Default colour for axis markers.
- BAR_GAP
- Default gap ratio between bars.
- BAR_
GAP_ INNER - Default gap ratio inside a group of bars.
- DIVERGING_
GRADIENT - Suggested colour scheme for a diverging gradient on a line. Uses a blue for negative values, a dark central value and red for positive values. Assumes a light background.
- GRID_
LINE_ COLOUR - Default colour for grid lines.
- GUIDE_
LINE_ COLOUR - Default colour for guide lines.
- LINEAR_
GRADIENT - Suggested colour scheme for a linear gradient on a line. Uses darker colours for lower values and lighter colours for higher values. Assumes a light background.
- SERIES_
COLOUR_ SCHEME - Arbitrary colours for a brighter palette than BATLOW
- STACK_
COLOUR_ SCHEME - Default colour scheme for stack. Assumes a light background with dark values for high values.
- TOOLTIP_
CURSOR_ DISTANCE - Default gap distance from cursor to tooltip when shown.
Traits§
- Into
Edge - Convert a type (e.g., a rotated label) into an edge layout for use with Chart.
- Into
Inner - Convert a type (e.g., a guide line) into an inner layout for use in a Chart.
- Tick
- A type that can be used as a tick on an axis. Try to rely on provided implementations.
- Tick
Format - Formats a tick value into a string. The precise format will be picked by the tick generator. For example if Timestamps is used and is only showing years then the format will be
YYYY.
Functions§
- Chart
- Renders an SVG chart.
Type Aliases§
- Diverging
Gradient - A diverging gradient of colours i.e., a gradient that tends to a central value then a second gradient away. Maps to a ColourScheme. Use with Line::with_gradient.
- Sequential
Gradient - A gradient of colours. Maps to a ColourScheme