@net-advantage/nabs-ui-charts
v0.63.0
Published
Reusable 2D chart controls for the Nabs UI library.
Readme
nabs-ui-charts
Reusable 2D chart controls for the Nabs UI library.
Includes:
TwoDChartfor line and bar charts (single or multi-series).PieChartfor single-series pie/donut charts.
Usage
import { PieChart, TwoDChart } from "@net-advantage/nabs-ui-charts";
const series = [
{ yAxis: "Mon", revenue: 18, volume: 12, forecast: 16 },
{ yAxis: "Tue", revenue: 26, volume: 17, forecast: 23 },
{ yAxis: "Wed", revenue: 22, volume: 15, forecast: 21 },
];
export function Example() {
return (
<>
<TwoDChart
chartType="line"
series={series}
valueName="revenue"
valueNames={["revenue", "volume", "forecast"]}
palette={["#3b82f6", "#ef4444", "#10b981"]}
xAxisName="Revenue"
topSpace={8}
yAxisMin={0}
yAxisMax={40}
yAxisInterval={5}
showLegend
/>
<PieChart
series={series}
valueName="revenue"
chartType="donut"
palette={["#3b82f6", "#ef4444", "#10b981"]}
showLegend
/>
</>
);
}Layout Model
TwoDChart uses a structured SVG layout tuned for dense charts:
- Plot area with explicit boundary.
- Horizontal guide lines derived from y-axis scale.
- Vertical guide lines aligned to category positions.
- Left y-axis tick labels.
- Footer label zone for category labels and x-axis/series label.
Props
seriesaccepts y-axis labels plus one or more named numeric values.valueNameselects a single named value (legacy/single-series mode).valueNamesselects one or more named values for multi-series mode (up to 10 series).paletteoptionally overrides series colors for this chart instance (first 10 entries are used).chartTypeswitches betweenlineandbarrendering.topSpaceadds top padding to the computed chart height (max value + topSpace).yAxisMindefines the minimum y-axis value.yAxisMaxdefines the maximum y-axis value.yAxisIntervaldefines the guide/tick interval betweenyAxisMinandyAxisMax.xAxisNameandshowXAxisNamecontrol the X-axis label display.showLegendcontrols whether the footer legend is rendered when multiple series are active.
PieChart
seriesaccepts y-axis labels plus numeric values.valueNameselects one named value to render as slices (single-series only).chartTypeswitches betweenpieanddonut.paletteoptionally overrides slice colors for this chart instance (first 10 entries are used).showLegendtoggles the legend beside the chart.
Notes
- Values are clamped to the configured y-axis range for drawing.
- Guide lines and y-axis ticks are generated from the configured min/max/interval.
- Multi-series rendering uses a generic 10-color palette with light/dark theme tokens.
- In multi-series mode, a footer legend is rendered under the x-axis name.
- Use the workbench Charts page to interactively tune range and interval settings.
