BarChart¶
A bar chart. The x field should contain a distinct value for each bar, while the y field will correspond to the height of each bar. The color field may be used to color each bar. In the case where there are multiple records for a single x value, aggregate may be used to combine values into a single bar.
This component can be found in the candela/plugins/vega
plugin.
Example¶
JavaScript
<body>
<script src="//unpkg.com/candela/dist/candela.min.js"></script>
<script>
var el = document.createElement('div')
document.body.appendChild(el);
var data = [];
for (var d = 0; d < 10; d += 1) {
data.push({
a: d,
b: d
});
}
var vis = new candela.components.BarChart(el, {
data: data,
x: 'a',
y: 'b'
});
vis.render();
</script>
</body>
Python
import pycandela
data = [{'a': d, 'b': d} for d in range(10)]
pycandela.components.BarChart(data=data, x='a', y='b')
R
library(candela)
candela('BarChart', data=mtcars, x='mpg', y='wt', color='disp')
Options¶
- data (Table)
- The data table.
- x (String)
- The x axis (bar position) field. Must contain numeric data. See Axis scales.
- xType (String)
- The data type for the
x
field. The default is"nominal"
. - y (String)
- The y axis (bar height) field. Must contain numeric data. See Axis scales.
- yType (String)
- The data type for the
y
field. The default is"quantitative"
. - color (String)
- The field used to color the bars.
- colorType (String)
- The data type for the
color
field. The default is"nominal"
. - aggregate (String)
- The aggregation mode for
y
values when thex
value is the same in multiple records. The default is"sum"
. - width (Number)
- Width of the chart in pixels. See Sizing.
- height (Number)
- Height of the chart in pixels. See Sizing.
- renderer (String)
- Whether to render in
"svg"
or"canvas"
mode (default"canvas"
).