Skip to content

Combined Charts

Combined charts in RareCharts do not require a separate class. They are built on top of DualAxes, which provides two vertical scales and allows each series to define its own rendering type. This makes it a natural foundation for mixing lines and bars within the same time-based chart.

To create a combined chart, you only need to specify the type for a particular series. All other series remain lines by default.

{
    name: 'Spread',
    axis: 'y2',
    type: 'bar',            // switch this series to bar
    color: '#000000',
    values: dates.map((dt, i) => ({ date: dt, value: spread[i] })),
}

The result is a combined chart where lines and bars coexist on the same timeline:

Each series explicitly declares two things: which axis it belongs to (y1 or y2) and how it should be rendered (line or bar). By design, Y1 is the right axis and Y2 is the left. You can mix any number of series in any configuration — multiple lines on one axis, multiple bars on the other, or both combined.

Per-series visual overrides continue to work exactly as in DualAxes. For example:

{
    name:        'Forecast',
    axis:        'y1',
    type:        'line',
    color:       '#00c97a',
    strokeDash:  'dashed',    // dashed line
    strokeWidth: 1.5,
    area:        true,        // fill under the line
    markers:     true,        // point markers
    markerShape: 'diamond',
    values: [...],
}

All standard DualAxes capabilities remain available in combined mode. This includes independent axis formatting (y1TickFormat, y2TickFormat), custom domains (y1Domain, y2Domain), axis titles, crosshair interaction, tooltips, end labels, bar grouping (overlap or cluster), bar width (barWidth, barWidthRatio), and curve interpolation for line series.

If you only need bars and do not require a second scale, assign all series to y1 and set showY2Axis: false. DualAxes calculates the domain from the Y1 series; without that option the left axis is still drawn, repeats the Y1 range and labels it with the Y2 format. Hidden, it gives its gutter back unless y2Title is set.

Bars take their width from barWidthRatio, a share of the smallest gap between bar dates, or in px from barWidth: on the chart for every bar series, or on one series for that series alone. With barGrouping: 'cluster', barWidth is the width of each bar, and the cluster is their sum, centred on the date:

new RareCharts.DualAxes('#chart', {
    barGrouping: 'cluster',
    barWidth:    6,                   // each bar of the cluster
}).setData([
    { name: 'Revenue', type: 'bar', barWidth: 10, values: [...] },   // this series only
    { name: 'Costs',   type: 'bar', values: [...] },
    { name: 'Margin',  type: 'line', axis: 'y2', values: [...] },
]);

A width too large for the space between dates is cut to it, so neighbouring bars and clusters touch but never overlap. The time scale is inset by half the widest bar or cluster: the first and last bars are drawn whole, and the lines start and end at the bar centres.

Logarithmic scale

Each axis has its own scale: y1Scale and y2Scale take 'linear' (default) or 'log'. A long-horizon index on Y1 reads honestly on a log axis — equal percentage moves get equal height — while a signed change on Y2 stays linear, because a log axis has no zero. A log axis follows the same rules as on Line: ticks on powers of ten (1-2-5 steps for a narrower range), a margin that is a factor of the data's span, zero and negative values on that axis skipped with one console warning, horizontal annotations at or below zero dropped. Bars on a log axis grow from the bottom of the axis instead of from zero.

scaleToggle adds a Log toggle pinned to the top right of the chart header, above the Y-axis labels — level with the timeframe buttons, which keep their place; it is filled while the axis is logarithmic and flips the scale on click. true drives Y1 — the right axis, usually the level or index — 'y2' the left one, 'both' both together (the toggle is then filled while either axis is logarithmic). From code, setYScale(type, { axis }) switches 'y1', 'y2' or 'both' (the default), and onScaleChange(fn) reports every switch as { scale, axis } — except a setYScale(…, { silent: true }). The demo opens on a linear axis and its toggle drives Y1 only: press Log and the first decades stop looking flat. The yearly change on Y2 stays linear.

const chart = new RareCharts.DualAxes('#chart', {
    y1Scale: 'log',
    scaleToggle: true,  // Y1; or 'y2', 'both'
});

chart.setYScale('linear', { axis: 'y1' });
chart.onScaleChange(e => console.log(e.axis, e.scale));

Combined chart options

Combined charts are DualAxes — all chart-level options are identical. See the full list on the Dual Axes page.

Per-series fields

The only thing that makes a chart “combined” is the type field on each series object:

Field Type Default Description
name string 'Series N' Series name — shown in the tooltip (the legend is not built from series; pass legend). Also the key that matches lines and bars across setData, so keep names unique.
axis 'y1' | 'y2' 'y1' Which Y axis this series plots against.
Y1 is right, Y2 is left.
type 'line' | 'bar' 'line' The key field.
Set to 'bar' to render this series as bars instead of a line.
color CSS color theme palette Series color — applies to both lines and bars.
barWidth number chart barWidth Bar width in px for this series (bars only); in a cluster, the width of this series' bar.
Overrides the chart-level barWidth and barWidthRatio; an invalid value falls back to them.
strokeWidth number theme strokeWidth (2) Line thickness in px (lines only).
strokeDash string — SVG stroke-dasharray for this series (lines only).
E.g. 'dashed', '4,3'.
curve string global curve Curve type override for this series (lines only).
area boolean global area Fill area under this series (lines only).
areaOpacity number global areaOpacity Per-series area opacity (lines only).
areaBaseline string | number global areaBaseline Area baseline anchor (lines only).
markers boolean global markers Point markers on this series (lines only); false hides them when the global markers is on.
markerShape string global markerShape Marker shape (lines only): 'circle', 'square', 'diamond', 'triangle', 'cross'.
markerSize number global markerSize Marker radius in px (lines only).
markerFill CSS color series color Marker fill color (lines only).
markerStroke CSS color theme background Marker outline color (lines only).
values array — [{date, value}, ...] — the data points; a point with a missing value (null, '') is dropped.