# Histogram¶

A histogram. The bin option specifies which field to summarize. By default, each record in the data table will contribute 1 to the bin’s total. Specifying an aggregate field will instead add up that field’s value for the each bin.

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 < 1000; d += 1) {
data.push({
a: Math.sqrt(-2*Math.log(Math.random()))*Math.cos(2*Math.PI*Math.random())
});
}

var vis = new candela.components.Histogram(el, {
data: data,
x: 'a',
width: 700,
height: 400
});
vis.render();
</script>
</body>


Python

import pycandela
from random import normalvariate as nv

data = [{'a': nv(0, 1)} for d in range(1000)]

pycandela.components.Histogram(data=data, x='a', width=700, height=400)


R

library(candela)

candela('Histogram', data=mtcars, x='mpg')


## Options¶

data (Table)
The data table.
x (String)
The x axis field, which is binned into a histogram.
xType (String)
The data type for the x field. The default is "nominal".
aggregate (String)
The aggregation mode for y values within each histogram bin. The default is "count", which does not use the y values but will count the number of records in the bin.
y (String)
The y axis field, which is used to determine the height of the histogram bar when aggregate is not set to "count".
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".
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").