The bar, line, area and plot charts take one PcacAxisConfig per axis, as xAxis and yAxis. Out of the box an axis is bare — labels, five ticks, no tick marks, no axis line, and a grid on one axis only — and each of those is a field on the object: hide, showGrid, ticks, tickSize, showLine, label and subLabels. Each part that's drawn also has a color field: labelColor, subLabelColor, tickLabelColor, tickColor, lineColor and gridColor.
Both charts below share the same two axis configs. Each column is one PcacAxisConfig.
xAxisyAxis<pcac-bar-vertical-chart>
<pcac-line-chart>
A few things to notice: the bar chart's x axis is a category axis, so ticks does nothing there (one tick per bar); the labels move with tickSize and the plot area gives up exactly that much room; the x axis's grid runs through the middle of each bar on the bar chart and through each tick on the line chart; and hiding an axis hands its margins to the plot rather than leaving a gap. The color pickers start on each part's default; pick a color and the chart takes it, or click theme to go back. See Colors below for what each one does.
const config = {
data: [ ... ],
// One PcacAxisConfig per axis. Every field is optional; leave the whole
// object out for a default axis (labels only, 5 ticks, grid on, 0-100).
xAxis: {
label: 'Product', // axis title, centered below the tick labels
tickSize: 12, // tick mark length in px - setting it is what turns the marks on
showLine: true, // solid line along the axis
lineColor: '#0d6efd' // its color (see Colors below)
},
yAxis: {
domainMax: 1000, // the value axis runs 0..domainMax (format: a PcacFormatEnum, e.g. Percentage)
label: 'Units sold',
subLabels: { min: 'Low', mid: 'Medium', max: 'High' }, // by position along the axis
ticks: 4, // requested tick (and grid line) count
showGrid: false // no horizontal grid lines
}
} as PcacBarVerticalChartConfig;
// Grids on both axes: the x axis's is off by default on this chart, so ask for it.
const gridded = {
data: [ ... ],
xAxis: { showGrid: true }
} as PcacLineChartConfig;
// Or hide an axis entirely: the space it took goes back to the plot.
const sparkline = {
data: [ ... ],
xAxis: { hide: true },
yAxis: { hide: true, showGrid: false }
} as PcacLineChartConfig;Each part of an axis has a color field. Give it any CSS color and only that part, on that axis, changes. Leave it out and the part keeps its default.
| Field | What it colors | Default |
|---|---|---|
| labelColor | The axis title (label) | Dark gray |
| subLabelColor | The subLabels row (all three) | Gray |
| tickLabelColor | The values along the axis | The page's text color |
| tickColor | The tick marks (needs tickSize) | Near black |
| lineColor | The axis line (needs showLine) | Near black |
| gridColor | This axis's grid lines (needs the grid on) | Light gray |
Three things to know:
rgb(), a named color, even currentColor.const config = {
data: [ ... ],
xAxis: {
showLine: true,
lineColor: '#0d6efd', // blue axis line
tickSize: 6,
tickColor: '#0d6efd', // blue tick marks
tickLabelColor: '#495057'
},
yAxis: {
label: 'Units sold',
labelColor: '#0d6efd',
gridColor: '#cfe2ff' // pale blue grid; the y axis's grid is on by default
}
} as PcacBarVerticalChartConfig;Every color is also a CSS custom property, so you can set the same thing in CSS instead — on the chart, on a wrapper, or on body — and every chart inside picks it up. Handy for a dark panel. If a chart's config also sets the color, the config wins.
/* Every chart inside .dark-panel */
.dark-panel {
--pcac-axis-label-color: #dee2e6;
--pcac-axis-sub-label-color: #adb5bd;
--pcac-axis-tick-label-color: #dee2e6;
--pcac-axis-tick-color: #adb5bd;
--pcac-axis-line-color: #adb5bd;
--pcac-grid-color: #495057;
}new gets both axes pre-filled. 0 keeps them off but pulls the labels in to the axis. enableZoomX for x, enableZoomY for y) is redrawn as you zoom and pan, with the same settings. $gray-* variables ($gray-900 marks and line, $gray-700 label, $gray-600 sub labels, $gray-200 grid), which the Sass override on the Theme page can also change for every chart at once.