useChart
Chart
stable
Stateless SVG chart engine powering <OrigamChart>. Computes every render-time descriptor needed for cartesian, polar, pie/donut, radar, bar, scatter, and stacked variants: viewBox, pixel-mapping scales, gridline ticks, per-series path/rect/circle descriptors, resolved legend entries, and an interactive hover state. Driven entirely by thunk options so it reacts to props, stores, or computed refs without re-instantiation.
API
Signature
Signature TypeScript complète extraite du fichier du composable.
Interfaces consommées
IUseChartOptions
IChartSeries
IChartScales
IChartPath
IChartLegendItem
IChartPoint
IChartTick
API
Paramètres
Paramètres d'entrée acceptés par ce composable.
- optionsrequisIUseChartOptions
- Configuration object with getter thunks for type, series, categories, stacked, stacking, donutHoleSize, colorScheme, smoothing, yMin, yMax, width, height, padding, and optional hiddenLabels and secondaryYAxis. All values are () => T functions so the composable reacts to any reactive source.
API
Valeurs de retour
Propriétés et méthodes exposées par l'objet retourné par le composable.
- viewBox
- Pre-formatted SVG viewBox attribute string ("0 0 W H"). The chart always renders at its full logical size; CSS handles visual scaling.
- scales
- Pixel-mapping functions: scales.x(value, dataIndex?, categoryCount?) and scales.y(value). Clamp values to the plot bounds so out-of-range data stays inside the SVG frame.
- ticks
- Gridline and axis-label descriptors for both axes. Bar charts swap the axis roles automatically (categorical along Y, value along X).
- secondaryTicks
- Tick descriptors for the optional right-hand Y axis. Populated only when secondaryYAxis is configured or a series carries yAxis === 1.
- paths
- Per-series render descriptors: path (line/area/pie/radar/polygon), rect (bar/column), or circle (scatter/markers). One entry per series for most types, one per data point for bar and scatter.
- legend
- Pre-resolved legend entries. Single-series pie/donut exposes one entry per slice (category); all other types expose one entry per series.
- hover
- Reactive hover state. Set by onPointHover when the user mouses over a data point. Null when no point is active.
- onPointHover
- Call with the hovered IChartPoint (or null on leave) to update the hover ref and drive the tooltip teleport.
- colorFor
- Resolve a series colour to a usable CSS string. Uses the series own color prop if set; otherwise cycles through the configured colorScheme (or the default TIntent palette).
- effectiveType
- Return the effective chart type for a series, falling back to the global options.type() when the series does not specify its own.
- percentValues
- Per-series, per-data-index percentage share of the column total. Populated only in stacking="percent" mode. Used by the tooltip to show the slice share.
Usage
Exemples
Extraits de code prêts à coller.
Line chart driven from props