The CSS selector or the element which the chart will be set to. D3 selection object can be specified. If other chart is set already, it will be replaced with the new one (only one chart can be set in one element).
If this option is not specified, the chart will be generated but not be set. Instead, we can access the element by chart.element and set it by ourselves.
When chart is not binded, c3 starts observing if chart.element is binded by MutationObserver. In this case, polyfill is required in IE9 and IE10 because they do not support MutationObserver. On the other hand, if chart always will be binded, polyfill will not be required because MutationObserver will never be called.
#chart
bindto: '#myContainer'
// or element
bindto: document.getElementById('myContainer')
// or D3 selection object
bindto: d3.select('#myContainer')
The desired width of the chart element.
If this option is not specified, the width of the chart will be calculated by the size of the parent element it's appended to.
undefined
size: {
width: 640
}
This option should be specified if possible because it can improve its performance because some size calculations will be skipped by an explicit value.
The desired height of the chart element.
If this option is not specified, the height of the chart will be calculated by the size of the parent element it's appended to.
undefined
size: {
height: 480
}
The padding on the top of the chart.
undefined
padding: {
top: 20
}
The padding on the right of the chart.
undefined
padding: {
right: 20
}
The padding on the bottom of the chart.
undefined
padding: {
bottom: 20
}
The padding on the left of the chart.
undefined
padding: {
left: 20
}
This option should be specified if possible because it can improve its performance because some size calculations will be skipped by an explicit value.
Set custom color pattern.
undefined
color: {
pattern: ['#1f77b4', '#aec7e8', ...]
}
not yet
Indicate if the chart should have interactions.
If false
is set, all of interactions (showing/hiding tooltip, selection, mouse events, etc) will be disabled.
true
interaction: {
enabled: false
}
Set duration of transition (in milliseconds) for chart animation.
If 0 or null set, transition will be skipped. So, this makes initial rendering faster especially in case you have a lot of data.
350
transition: {
duration: 500
}
Set a callback to execute when the chart is initialized.
function () {}
oninit: function () { ... }
Set a callback which is executed when the chart is rendered. Basically, this callback will be called in each time when the chart is redrawed.
function () {}
onrendered: function () { ... }
Set a callback to execute when mouse enters the chart.
function () {}
onmouseover: function () { ... }
Set a callback to execute when mouse leaves the chart.
function () {}
onmouseout: function () { ... }
Set a callback to execute when user resizes the screen.
function () {}
onresize: function () { ... }
Set a callback to execute when screen resize finished.
function () {}
onresized: function () { ... }
Load a CSV or JSON file from a URL. Note that this will not work if loading via the "file://" protocol as the most browsers will block XMLHTTPRequests.
var chart = c3.generate({
data: {
url: '/data/c3_test.csv'
}
});
Parse a JSON object for data. See also data.keys.
var chart = c3.generate({
data: {
json: [
{name: 'www.site1.com', upload: 200, download: 200, total: 400},
{name: 'www.site2.com', upload: 100, download: 300, total: 400},
{name: 'www.site3.com', upload: 300, download: 200, total: 500},
{name: 'www.site4.com', upload: 400, download: 100, total: 500}
],
keys: {
// x: 'name', // it's possible to specify 'x' when category axis
value: ['upload', 'download']
}
},
axis: {
x: {
// type: 'category'
}
}
});
Load data from a multidimensional array, with the first element containing the data names, the following containing related data in that order.
rows: [
['data1', 'data2', 'data3'],
[90, 120, 300],
[40, 160, 240],
[50, 200, 290],
[120, 160, 230],
[80, 130, 300],
[90, 220, 320]
]
Load data from a multidimensional array, with each element containing an array consisting of a datum name and associated data values.
columns: [
['data1', 30, 20, 50, 40, 60, 50],
['data2', 200, 130, 90, 240, 130, 220],
['data3', 300, 200, 160, 400, 250, 250]
]
Used if loading JSON via data.url:
{data: {mimeType: 'json'}}
Choose which JSON object keys correspond to desired data.
var chart = c3.generate({
data: {
json: [
{name: 'www.site1.com', upload: 200, download: 200, total: 400},
{name: 'www.site2.com', upload: 100, download: 300, total: 400},
{name: 'www.site3.com', upload: 300, download: 200, total: 500},
{name: 'www.site4.com', upload: 400, download: 100, total: 500}
],
keys: {
// x: 'name', // it's possible to specify 'x' when category axis
value: ['upload', 'download']
}
},
axis: {
x: {
// type: 'category'
}
}
});
Specify the key of x values in the data.
We can show the data with non-index x values by this option. This option is required when the type of x axis is timeseries. If this option is set on category axis, the values of the data on the key will be used for category names.
undefined
data: {
x: 'date'
}
Specify the keys of the x values for each data.
This option can be used if we want to show the data that has different x values.
{}
data: {
xs: {
data1: 'x1',
data2: 'x2'
}
}
data.x should be used if the all of data have same x values.
Set a format to parse string specified as x.
%Y-%m-%d
data: {
xFormat: '%Y-%m-%d %H:%M:%S'
}
not yet
not yet
Set custom data name.
{}
data: {
names: {
data1: 'Data Name 1',
data2: 'Data Name 2'
}
}
Set custom data class.
If this option is specified, the element g for the data has an additional class that has the prefix c3-target- (e.g. c3-target-additional-data1-class).
{}
data: {
classes: {
data1: 'additional-data1-class',
data2: 'additional-data2-class'
}
}
Set groups for the data for stacking.
[]
data: {
groups: [
['data1', 'data2'],
['data3']
]
}
Set y axis the data related to. y and y2 can be used.
{}
data: {
axes: {
data1: 'y',
data2: 'y2'
}
}
Set chart type at once.
If this option is specified, the type will be applied to every data. This setting can be overwritten by data.types.
line
data: {
type: 'bar'
}
Set chart type for each data.
This setting overwrites data.type setting.
{}
data: {
types: {
data1: 'bar'
data2: 'spline'
}
}
Show labels on each data points.
false
data: {
labels: true
}
Set formatter function for data labels.
The formatter function receives 4 arguments such as v, id, i, j and it must return a string that will be shown as the label. The arguments are:
Formatter function can be defined for each data by specifying as an object and D3 formatter function can be set (e.g. d3.format('$'))
{}
data: {
labels: {
format: function (v, id, i, j) { ... }
// it's possible to set for each data
//format: {
// data1: function (v, id, i, j) { ... },
// ...
//}
}
}
Define the order of the data.
This option changes the order of stacking the data and pieces of pie/donut. If null
specified, it will be the order the data loaded. If function specified, it will be used to sort the data and it will receive the data as argument.
null
desc
data: {
order: 'asc'
}
Define regions for each data.
The values must be an array for each data and it should include an object that has start, end, style. If start is not set, the start will be the first data point. If end is not set, the end will be the last data point.
Currently this option supports only line chart and dashed style. If this option specified, the line will be dashed only in the regions.
{}
data: {
regions: {
data1: [{'start':1, 'end':2, 'style':'dashed'},{'start':3}],
...
}
}
Set color converter function.
This option should a function and the specified function receives color (e.g. '#ff0000') and d that has data parameters like id, value, index, etc. And it must return a string that represents color (e.g. '#00ff00').
undefined
data: {
color: function (color, d) { ... }
}
Set color for each data.
{}
data: {
colors: {
data1: '#ff0000',
...
}
}
Hide each data when the chart appears.
If true
specified, all of data will be hidden. If multiple ids specified as an array, those will be hidden.
false
data: {
// all of data will be hidden
hide: true
// specified data will be hidden
hide: ['data1', ...]
}
This option does not hide legends, so we need to use legend.hide option together if we want to hide legend too.
Set text displayed when empty data.
""
data: {
empty: {
label: {
text: "No Data"
}
}
}
Set data selection enabled.
If this option is set true
, we can select the data points and get/set its state of selection by API (e.g. select, unselect, selected).
false
data: {
selection: {
enabled: true
}
}
Set grouped selection enabled.
If this option set true
, multiple data points that have same x value will be selected by one selection.
false
data: {
selection: {
grouped: true
}
}
Set multiple data points selection enabled.
If this option set true
, multiple data points can have the selected state at the same time. If false
set, only one data point can have the selected state and the others will be unselected when the new data point is selected.
true
data: {
selection: {
multiple: true
}
}
Enable to select data points by dragging.
If this option set true
, data points can be selected by dragging.
If this option set true
, scrolling on the chart will be disabled because dragging event will handle the event.
false
data: {
selection: {
draggable: true
}
}
Set a callback for each data point to determine if it's selectable or not.
The callback will receive d as an argument and it has some parameters like id, value, index. This callback should return boolean.
function () { return true; }
data: {
selection: {
isselectable: function (d) { ... }
}
}
Set a callback for click event on each data point.
This callback will be called when each data point clicked and will receive d and element as the arguments. d is the data clicked and element is the element clicked. In this callback, this will be the Chart object.
function () {}
data: {
onclick: function (d, element) { ... }
}
Set a callback for mouseover event on each data point.
This callback will be called when mouse cursor moves onto each data point and will receive d as the argument. d is the data where mouse cursor moves onto. In this callback, this will be the Chart object.
function () {}
data: {
onmouseover: function (d) { ... }
}
Set a callback for mouseout event on each data point.
This callback will be called when mouse cursor moves out each data point and will receive d as the argument. d is the data where mouse cursor moves out. In this callback, this will be the Chart object.
function () {}
data: {
onmouseout: function (d) { ... }
}
not yet
not yet
not yet
not yet
Switch x and y axis position.
false
axis: {
rotated: true
}
Show or hide x axis.
true
axis: {
x: {
show: true
}
}
Set type of x axis.
indexed
axis: {
x: {
type: 'timeseries'
}
}
Set how to treat the timezone of x values.
If true, treat x value as localtime. If false, convert to UTC internally.
true
axis: {
x: {
localtime: true
}
}
Set category names on category axis.
This must be an array that includes category names in string. If category names are included in the date by data.x option, this is not required.
[]
axis: {
x: {
categories: ['Category 1', 'Category 2', ...]
}
}
Centerise ticks on category axis.
false
axis: {
x: {
tick: {
centered: true
}
}
}
A function to format tick value. Format string is also available for timeseries data.
undefined
axis: {
x: {
tick: {
format: function (x) { return x.getFullYear(); }
}
}
}
Setting for culling ticks.
If true
is set, the ticks will be culled, then only limitted tick text will be shown. This option does not hide the tick lines. If false
is set, all of ticks will be shown.
We can change the number of ticks to be shown by axis.x.tick.culling.max.
true
for indexed axis and timeseries axisfalse
for category axisaxis: {
x: {
tick: {
culling: false
}
}
}
The number of tick texts will be adjusted to less than this value.
10
axis: {
x: {
tick: {
culling: {
max: 5
}
}
}
}
The number of x axis ticks to show.
This option hides tick lines together with tick text. If this option is used on timeseries axis, the ticks position will be determined precisely and not nicely positioned (e.g. it will have rough second value).
undefined
axis: {
x: {
tick: {
count: 5
}
}
}
Fit x axis ticks.
If true
set, the ticks will be positioned nicely. If false
set, the ticks will be positioned according to x value of the data points.
true
axis: {
x: {
tick: {
fit: true
}
}
}
Set the x values of ticks manually.
If this option is provided, the position of the ticks will be determined based on those values. This option works with timeseries data and the x values will be parsed accoding to the type of the value and data.xFormat option.
null
axis: {
x: {
tick: {
values: [1, 2, 4, 8, 16, 32, ...]
}
}
}
Rotate x axis tick text.
If you set negative value, it will rotate to opposite direction.
0
axis: {
x: {
tick: {
rotate: 60
}
}
}
Show x axis outer tick.
true
axis: {
x: {
tick: {
outer: false
}
}
}
not yet
not yet
Set max value of x axis range.
undefined
axis: {
x: {
max: 100
}
}
Set min value of x axis range.
undefined
axis: {
x: {
min: -100
}
}
Set padding for x axis.
If this option is set, the range of x axis will increase/decrease according to the values. If no padding is needed in the ragen of x axis, 0
should be set. On category axis, this option will be ignored.
{}
axis: {
x: {
padding: {
left: 0,
right: 0
}
}
}
Set height of x axis.
The height of x axis can be set manually by this option. If you need more space for x axis, please use this option for that. The unit is pixel
.
undefined
axis: {
x: {
height: 20
}
}
Set default extent for subchart and zoom. This can be an array or function that returns an array.
undefined
axis: {
x: {
extent: [5, 10]
}
}
Set label on x axis.
You can set x axis label and change its position by this option. string
and object
can be passed and we can change the poisiton by passing object
that has position key. Available position differs according to the axis direction (vertical or horizontal). If string
set, the position will be the default.
If it's horizontal axis:
[default]
If it's vertical axis:
[default]
undefined
axis: {
x: {
label: 'Your X Axis'
}
}
axis: {
x: {
label: {
text: 'Your X Axis',
position: 'outer-center'
}
}
}
Show or hide y axis.
true
axis: {
y: {
show: false
}
}
Show y axis inside of the chart.
false
axis: {
y: {
inner: true
}
}
not yet
Set max value of y axis.
Padding will be added based on this value, so if you don't need the padding, please set axis.y.padding to disable it (e.g. axis.y.padding = 0).
undefined
axis: {
y: {
max: 1000
}
}
Set min value of y axis.
Padding will be added based on this value, so if you don't need the padding, please set axis.y.padding to disable it (e.g. axis.y.padding = 0).
undefined
axis: {
y: {
min: 1000
}
}
Change the direction of y axis.
If true
set, the direction will be from the top to the bottom.
false
axis: {
y: {
inverted: true
}
}
Set center value of y axis.
undefined
axis: {
y: {
center: 0
}
}
Set label on y axis.
You can set y axis label and change its position by this option. This option works in the same way as axis.x.label.
undefined
axis: {
y: {
label: 'Your Y Axis'
}
}
axis: {
y: {
label: {
text: 'Your Y Axis',
position: 'outer-middle'
}
}
}
Set formatter for y axis tick text.
This option accepts d3.format object as well as a function you define.
undefined
axis: {
y: {
tick: {
format: d3.format('$,')
//or format: function (d) { return '$' + d; }
}
}
}
Show or hide outer tick.
undefined
axis: {
y: {
tick: {
outer: false
}
}
}
Set y axis tick values manually.
undefined
axis: {
y: {
tick: {
values: [100, 1000, 10000]
}
}
}
Set the number of y axis ticks.
The position of the ticks will be calculated precisely, so the values on the ticks will not be rounded nicely. In the case, axis.y.tick.format or axis.y.tick.values will be helpful.
undefined
axis: {
y: {
tick: {
count: 5
}
}
}
not yet
not yet
Set padding for y axis.
You can set padding for y axis to create more space on the edge of the axis. This option accepts object
and it can include top and bottom. top, bottom will be treated as pixels.
undefined
axis: {
y: {
padding: {
top: 100,
bottom: 100
}
}
}
Set default range of y axis.
This option set the default value for y axis when there is no data on init.
undefined
axis: {
y: {
default: [0, 1000]
}
}
Show or hide y2 axis.
false
axis: {
y2: {
show: true
}
}
Show y2 axis inside of the chart.
false
axis: {
y2: {
inner: true
}
}
Set max value of y2 axis.
undefined
axis: {
y2: {
max: 1000
}
}
Set min value of y2 axis.
undefined
axis: {
y2: {
min: -1000
}
}
Change the direction of y2 axis.
If true
set, the direction will be from the top to the bottom.
false
axis: {
y2: {
inverted: true
}
}
Set center value of y2 axis.
undefined
axis: {
y2: {
center: 0
}
}
Set label on y2 axis.
You can set y2 axis label and change its position by this option. This option works in the same way as axis.x.label.
undefined
axis: {
y2: {
label: 'Your Y2 Axis'
}
}
axis: {
y2: {
label: {
text: 'Your Y2 Axis',
position: 'outer-middle'
}
}
}
Set formatter for y axis tick text.
This option works in the same way as axis.y.format.
undefined
axis: {
y2: {
tick: {
format: d3.format('$,')
//or format: function (d) { return '$' + d; }
}
}
}
Show or hide y2 axis outer tick.
undefined
axis: {
y2: {
tick: {
outer: false
}
}
}
Set y2 axis tick values manually.
undefined
axis: {
y2: {
tick: {
values: [100, 1000, 10000]
}
}
}
Set the number of y2 axis ticks.
This works in the same way as axis.y.tick.count.
undefined
axis: {
y2: {
tick: {
count: 5
}
}
}
Set padding for y2 axis.
This works in the same way as axis.y.padding.
undefined
axis: {
y2: {
padding: {
top: 100,
bottom: 100
}
}
}
Set default range of y2 axis.
This option set the default value for y2 axis when there is no data on init.
undefined
axis: {
y2: {
default: [0, 1000]
}
}
Show grids along x axis.
false
grid: {
x: {
show: true
}
}
Show additional grid lines along x axis.
This option accepts array
including object
that has value, text, position and class. text, position and class are optional. For position, start, middle and end (default) are available.
If x axis is category axis, value can be category name. If x axis is timeseries axis, value can be date string, Date object and unixtime integer.
[]
grid: {
x: {
lines: [
{value: 2, text: 'Label on 2'},
{value: 5, text: 'Label on 5', class: 'label-5'},
{value: 6, text: 'Label on 6', position: 'start'}
]
}
}
Show grids along y axis.
false
grid: {
y: {
show: true
}
}
Show additional grid lines along y axis.
This option accepts array
including object
that has value, text, position and class.
[]
grid: {
y: {
lines: [
{value: 100, text: 'Label on 100'},
{value: 200, text: 'Label on 200', class: 'label-200'},
{value: 300, text: 'Label on 300', position: 'middle'}
]
}
}
not yet
Show rectangles inside the chart.
This option accepts array
including object
that has axis, start, end and class. The keys start, end and class are optional.
axis must be x, y or y2. start and end should be the value where regions start and end. If not specified, the edge values will be used. If timeseries x axis, date string, Date object and unixtime integer can be used. If class is set, the region element will have it as class.
[]
regions: [
{axis: 'x', start: 1, end: 4, class: 'region-1-4'}
]
Show or hide legend.
true
legend: {
show: true
}
Hide legend
If true
given, all legend will be hidden. If string
or array
given, only the legend that has the id will be hidden.
false
legend: {
hide: true
//or hide: 'data1'
//or hide: ['data1', 'data2']
}
Change the position of legend.
Currently bottom, right and inset are supported.
bottom
legend: {
position: 'bottom'
}
Change inset legend attributes.
This option accepts object
that has the keys anchor, x, y and step.
anchor decides the position of the legend. These anchors are available:
x and y set the position of the legend based on the anchor.
step defines the max step the legend has (e.g. If 2 set and legend has 3 legend item, the legend 2 columns).
{
anchor: 'top-left',
x: 10,
y: 0,
step: undefined
}
legend: {
inset: {
anchor: 'top-right',
x: 20,
y: 10,
step: 2
}
}
Set click event handler to the legend item.
undefined
legend: {
item: {
onclick: function (id) { ... }
}
}
Set mouseover event handler to the legend item.
undefined
legend: {
item: {
onmouseover: function (id) { ... }
}
}
Set mouseout event handler to the legend item.
undefined
legend: {
item: {
onmouseout: function (id) { ... }
}
}
Show or hide tooltip.
true
tooltip: {
show: false
}
Set if tooltip is grouped or not for the data points.
true
tooltip: {
grouped: false
}
Set format for the title of tooltip.
Specified function receives x of the data point to show.
undefined
tooltip: {
format: {
title: function (x) { return 'Data ' + x; }
}
}
Set format for the name of each data in tooltip.
Specified function receives name, ratio, id and index of the data point to show. ratio will be undefined
if the chart is not donut/pie/gauge.
undefined
tooltip: {
format: {
name: function (name, ratio, id, index) { return name; }
}
}
Set format for the value of each data in tooltip.
Specified function receives name, ratio, id and index of the data point to show. ratio will be undefined
if the chart is not donut/pie/gauge.
If undefined
returned, the row of that value will be skipped.
undefined
tooltip: {
format: {
value: function (value, ratio, id, index) { return ratio; }
}
}
Set custom position for the tooltip.
This option can be used to modify the tooltip position by returning object
that has top and left.
undefined
tooltip: {
position: function (data, width, height, element) {
return {top: 0, left: 0};
}
}
Set custom HTML for the tooltip.
Specified function receives data, defaultTitleFormat, defaultValueFormat and color of the data point to show. If tooltip.grouped is true
, data includes multiple data points.
undefined
tooltip: {
contents: function (d, defaultTitleFormat, defaultValueFormat, color) {
return ... // formatted html as you want
}
}
Show sub chart on the bottom of the chart.
false
subchart: {
show: true
}
Change the height of the subchart.
undefined
subchart: {
size: {
height: 20
}
}
Set callback for brush event.
Specified function receives the current zoomed x domain.
undefined
subchart: {
onbrush: function (domain) { ... }
}
Enable zooming.
false
zoom: {
enabled: false
}
Enable to rescale after zooming.
If true
set, y domain will be updated according to the zoomed region.
false
zoom: {
rescale: true
}
Change zoom extent.
[1, 10]
zoom: {
extent: [1, 100] // enable more zooming
}
Set callback that is called when the chart is zooming.
Specified function receives the zoomed domain.
undefined
zoom: {
onzoom: function (domain) { ... }
}
Set callback that is called when zooming starts.
Specified function receives the zoom event.
undefined
zoom: {
onzoomstart: function (event) { ... }
}
Set callback that is called when zooming ends.
Specified function receives the zoomed domain.
undefined
zoom: {
onzoomend: function (domain) { ... }
}
Whether to show each point in line.
true
point: {
show: false
}
The radius size of each point.
2.5
point: {
r: 5
}
Whether to expand each point on focus.
true
point: {
focus: {
expand: {
enabled: true
}
}
}
The radius size of each point on focus.
point.r * 1.75
point: {
focus: {
expand: {
r: 1
}
}
}
The radius size of each point on selected.
point.r * 4
point: {
select: {
r: 3
}
}
Set if null data point will be connected or not.
If true
set, the region of null data will be connected without any data point. If false
set, the region of null data will not be connected and get empty.
false
line: {
connectNull: true
}
Change step type for step chart.
step, step-before and step-after can be used.
'step'
line: {
step: {
type: 'step-after'
}
}
Set if min or max value will be 0 on area chart.
true
area: {
zerobased: false
}
Change the width of bar chart.
auto
bar: {
width: 10
}
Change the width of bar chart by ratio.
0.6
bar: {
width: {
ratio: 0.2
}
}
Set if min or max value will be 0 on bar chart.
true
bar: {
zerobased: false
}
Show or hide label on each pie piece.
true
pie: {
label: {
show: false
}
}
Set formatter for the label on each pie piece.
undefined
pie: {
label: {
format: function (value, ratio, id) {
return d3.format('$')(value);
}
}
}
Set threshold to show/hide labels.
0.05
pie: {
label: {
threshold: 0.1
}
}
Enable or disable expanding pie pieces.
true
pie: {
expand: false
}
Show or hide label on each donut piece.
true
donut: {
label: {
show: false
}
}
Set formatter for the label on each donut piece.
undefined
donut: {
label: {
format: function (value, ratio, id) {
return d3.format('$')(value);
}
}
}
Set threshold to show/hide labels.
0.05
donut: {
label: {
threshold: 0.1
}
}
Enable or disable expanding donut pieces.
true
donut: {
expand: false
}
Set width of donut chart.
auto
donut: {
width: 10
}
Set title of donut chart.
''
donut: {
title: 'Title'
}
Show or hide label on gauge.
true
gauge: {
label: {
show: false
}
}
Set formatter for the label on gauge.
undefined
gauge: {
label: {
format: function (value, ratio) {
return value;
}
}
}
Enable or disable expanding gauge.
true
gauge: {
expand: false
}
Set min value of the gauge.
0
gauge: {
min: -100
}
Set max value of the gauge.
100
gauge: {
max: 200
}
Set units of the gauge.
undefined
gauge: {
units: ' %'
}
Set width of gauge chart.
auto
gauge: {
width: 10
}
This API highlights specified targets and fade out the others.
You can specify multiple targets by giving an array that includes id as String
. If no argument is given, all of targets will be highlighted.
.focus(targetIds)
targetIds String
or Array
Target ids to be highlighted.
// data1 will be highlighted and the others will be faded out
chart.focus('data1');
// data1 and data2 will be highlighted and the others will be faded out
chart.focus(['data1', 'data2']);
// all targets will be highlighted
chart.focus();
This API fades out specified targets and reverts the others.
You can specify multiple targets by giving an array that includes id as String
. If no argument is given, all of targets will be faded out.
.defocus(targetIds)
targetIds String
or Array
Target ids to be faded out.
// data1 will be faded out and the others will be reverted.
chart.defocus('data1');
// data1 and data2 will be faded out and the others will be reverted.
chart.defocus(['data1', 'data2']);
// all targets will be faded out.
chart.defocus();
This API reverts specified targets.
You can specify multiple targets by giving an array that includes id as String
. If no argument is given, all of targets will be reverted.
.revert(targetIds)
targetIds String
or Array
Target ids to be reverted.
// data1 will be reverted.
chart.revert('data1');
// data1 and data2 will be reverted.
chart.revert(['data1', 'data2']);
// all targets will be reverted.
chart.revert();
This API shows specified targets.
You can specify multiple targets by giving an array that includes id as String
. If no argument is given, all of targets will be shown.
.show(targetIds, options)
targetIds String
or Array
Target ids to be shown.
options Object
If withLegend is set true
, legend will be shown together with the specified data.
// data1 will be shown.
chart.show('data1');
// data1 and data2 will be shown.
chart.show(['data1', 'data2']);
// all targets will be shown.
chart.show();
// data1 will be shown together with its legend.
chart.show('data1', {withLegend: true});
This API hides specified targets.
You can specify multiple targets by giving an array that includes id as String
. If no argument is given, all of targets will be hidden.
.hide(targetIds, options)
targetIds String
or Array
Target ids to be hidden.
options Object
If withLegend is set true
, legend will be hidden together with the specified data.
// data1 will be hidden.
chart.hide('data1');
// data1 and data2 will be hidden.
chart.hide(['data1', 'data2']);
// all targets will be hidden.
chart.hide();
// data1 will be hidden together with its legend.
chart.hide('data1', {withLegend: true});
This API toggles (shows or hides) specified targets.
You can specify multiple targets by giving an array that includes id as String
. If no argument is given, all of targets will be toggles.
.toggle(targetIds, options)
targetIds String
or Array
Target ids to be toggled.
options Object
If withLegend is set true
, legend will be toggled together with the specified data.
// data1 will be toggled.
chart.toggle('data1');
// data1 and data2 will be toggled.
chart.toggle(['data1', 'data2']);
// all targets will be toggled.
chart.toggle();
// data1 will be toggled together with its legend.
chart.toggle('data1', {withLegend: true});
Load data to the chart.
You can specify multiple targets by giving an array that includes id as String
. If no argument is given, all of targets will be toggles.
.load(args)
args Object
If url, json, rows and columns given, the data will be loaded. If data that has the same target id is given, the chart will be updated. Otherwise, new target will be added.
If classes given, the classes specified by data.classes will be updated. classes must be Object
that has target id as keys.
If categories given, the categories specified by axis.x.categories or data.x will be updated. categories must be Array
.
If axes given, the axes specified by data.axes will be updated. axes must be Object
that has target id as keys.
If colors given, the colors specified by data.colors will be updated. colors must be Object
that has target id as keys.
If type or types given, the type of targets will be updated. type must be String
and types must be Object
.
If unload given, data will be unloaded before loading new data. If true
given, all of data will be unloaded. If target ids given as String
or Array
, specified targets will be unloaded.
If done given, the specified function will be called after data loded.
unload should be used if some data needs to be unloaded simultaneously. If you call unload API soon after/before load instead of unload param, chart will not be rendered properly because of cancel of animation.
done will be called after data loaded, but it's not after rendering. It's because rendering will finish after some transition and there is some time lag between loading and rendering.
// Load data1 and unload data2 and data3
chart.load({
columns: [
['data1, 100, 200, 150, ...],
...
],
unload: ['data2', 'data3']
});
Unload data to the chart.
You can specify multiple targets by giving an array that includes id as String
. If no argument is given, all of targets will be toggles.
.unload(args)
args Object
If ids given, the data that has specified target id will be unloaded. ids should be String
or Array
. If ids is not specified, all data will be unloaded.
If done given, the specified function will be called after data loded.
If you call load API soon after/before unload, unload param of load should be used. Otherwise chart will not be rendered properly because of cancel of animation.
done will be called after data loaded, but it's not after rendering. It's because rendering will finish after some transition and there is some time lag between loading and rendering.
// Unload data2 and data3
chart.unload({
ids: ['data2', 'data3']
});
Flow data to the chart.
By this API, you can append new data points to the chart.
.flow(args)
args Object
If json, rows and columns given, the data will be loaded. If data that has the same target id is given, the chart will be appended. Otherwise, new target will be added. One of these is required when calling. If json specified, keys is required as well as data.json
If to is given, the lower x edge will move to that point. If not given, the lower x edge will move by the number of given data points.
If length is given, the lower x edge will move by the number of this argument.
If duration is given, the duration of the transition will be specified value. If not given, transition.duration will be used as default.
If done is given, the specified function will be called when flow ends.
// 2 data points will be apprended to the tail and popped from the head.
// After that, 4 data points will be appended and no data points will be poppoed.
chart.flow({
columns: [
['x', '2013-01-11', '2013-01-21'],
['data1', 500, 200],
['data2', 100, 300],
['data3', 200, 120]
],
done: function () {
chart.flow({
columns: [
['x', '2013-02-11', '2013-02-12', '2013-02-13', '2013-02-14'],
['data1', 200, 300, 100, 250],
['data2', 100, 90, 40, 120],
['data3', 100, 100, 300, 500]
],
length: 0
});
}
});
Change data point state to selected.
By this API, you can select data points. To use this API, data.selection.enabled needs to be set true
.
.select(ids, indices, resetOthers)
ids Array
Specify target ids to be selected. If this argument is not given, all targets will be the candidate.
indices Array
Specify indices to be selected. If this argument is not given, all data points will be the candidate.
resetOthers boolean
If this argument is set true
, the data points that are not specified by ids, indices will be unselected.
// all data points of data1 will be selected.
chart.select(['data1']);
// 3 data points on index 1, 3, 5 of data1 will be selected.
chart.select(['data1'], [1,3,5]);
Change data point state to unselected.
By this API, you can unselect data points. To use this API, data.selection.enabled needs to be set true
.
.unselect(ids, indices)
ids Array
Specify target ids to be unselected. If this argument is not given, all targets will be the candidate.
indices Array
Specify indices to be unselected. If this argument is not given, all data points will be the candidate.
// all data points of data1 will be unselected.
chart.unselect(['data1']);
// 3 data points on index 1, 3, 5 of data1 will be unselected.
chart.unselect(['data1'], [1,3,5]);
Get selected data points.
By this API, you can get selected data points information. To use this API, data.selection.enabled needs to be set true
.
.selected(targetId)
targetId String
You can filter the result by giving target id that you want to get. If not given, all of data points will be returned.
// all selected data points will be returned.
chart.selected();
// all selected data points of data1 will be returned.
chart.selected('data1');
Change the type of the chart.
.transform(type, targetIds)
type String
Specify the type to be transformed. The types listed in data.type can be used.
targetIds String
or Array
Specify targets to be transformed. If not given, all targets will be the candidate.
// all targets will be bar chart.
chart.transform('bar');
// only data1 will be bar chart.
chart.transform('bar', 'data1');
// only data1 and data2 will be bar chart.
chart.transform('bar', ['data1', 'data2']);
Update groups for the targets.
.groups(groups)
groups Array
This argument needs to be an Array
that includes one or more Array
that includes target ids to be grouped.
// data1 and data2 will be a new group.
chart.groups([['data1', 'data2']]);
Update x grid lines.
.xgrids(grids)
grids Array
X grid lines will be replaced with this argument. The format of this argument is the same as grid.x.lines.
// Show 2 x grid lines
chart.xgrids([
{value: 1, text:'Label 1'},
{value: 4, text: 'Label 4'}
]);
Add x grid lines.
This API adds new x grid lines instead of replacing like xgrids.
.xgrids.add(grids)
grids Array
or Object
New x grid lines will be added. The format of this argument is the same as grid.x.lines and it's possible to give an Object
if only one line will be added.
// Add a new x grid line
chart.xgrids.add(
{value: 4, text: 'Label 4'}
);
// Add new x grid lines
chart.xgrids.add([
{value: 2, text: 'Label 2'},
{value: 4, text: 'Label 4'}
]);
Remove x grid lines.
This API removes x grid lines.
.xgrids.remove(args)
args Object
This argument should include value or class. If value is given, the x grid lines that have specified x value will be removed. If class is given, the x grid lines that have specified class will be removed. If args is not given, all of x grid lines will be removed.
// x grid line on x = 2 will be removed
chart.xgrids.remove({value: 2});
// x grid lines that have 'grid-A' will be removed
chart.xgrids.remove({class: 'grid-A'});
// all of x grid lines will be removed
chart.xgrids.remove();
Update y grid lines.
.ygrids(grids)
grids Array
X grid lines will be replaced with this argument. The format of this argument is the same as grid.y.lines.
// Show 2 y grid lines
chart.ygrids([
{value: 100, text:'Label 1'},
{value: 400, text: 'Label 4'}
]);
Add y grid lines.
This API adds new y grid lines instead of replacing like ygrids.
.ygrids.add(grids)
grids Array
or Object
New y grid lines will be added. The format of this argument is the same as grid.y.lines and it's possible to give an Object
if only one line will be added.
// Add a new y grid line
chart.ygrids.add(
{value: 400, text: 'Label 4'}
);
// Add new y grid lines
chart.ygrids.add([
{value: 200, text: 'Label 2'},
{value: 400, text: 'Label 4'}
]);
Remove y grid lines.
This API removes y grid lines.
.ygrids.remove(args)
args Object
This argument should include value or class. If value is given, the y grid lines that have specified y value will be removed. If class is given, the y grid lines that have specified class will be removed. If args is not given, all of y grid lines will be removed.
// y grid line on y = 200 will be removed
chart.ygrids.remove({value: 200});
// y grid lines that have 'grid-A' will be removed
chart.ygrids.remove({class: 'grid-A'});
// all of y grid lines will be removed
chart.ygrids.remove();
Update regions.
.regions(regions)
regions Array
Regions will be replaced with this argument. The format of this argument is the same as regions.
// Show 2 regions
chart.regions([
{axis: 'x', start: 5, class: 'regionX'},
{axis: 'y', end: 50, class: 'regionY'}
]);
Add new region.
This API adds new region instead of replacing like regions.
.regions.add(regions)
regions Array
or Object
New region will be added. The format of this argument is the same as regions and it's possible to give an Object
if only one region will be added.
// Add a new region
chart.regions.add(
{axis: 'x', start: 5, class: 'regionX'}
);
// Add new regions
chart.regions.add([
{axis: 'x', start: 5, class: 'regionX'},
{axis: 'y', end: 50, class: 'regionY'}
]);
Remove regions.
This API removes regions.
.regions.remove(args)
args Object
This argument should include classes. If classes is given, the regions that have one of the specified classes will be removed. If args is not given, all of regions will be removed.
// regions that have 'region-A' or 'region-B' will be removed.
chart.regions.remove({classes: ['region-A', 'region-B']});
// all of regions will be removed.
chart.regions.remove();
Get data loaded in the chart.
.data(targetIds)
targetIds String
or Array
If this argument is given, this API returns the specified target data. If this argument is not given, all of data will be returned.
// Get only data1 data
chart.data('data1');
// Get data1 and data2 data
chart.data(['data1', 'data2']);
// Get all data
chart.data();
Get data shown in the chart.
.data.shown(targetIds)
targetIds String
or Array
If this argument is given, this API filters the data with specified target ids. If this argument is not given, all shown data will be returned.
// Get shown data by filtering to include only data1 data
chart.data.shown('data1');
// Get shown data by filtering to include data1 and data2 data
chart.data.shown(['data1', 'data2']);
// Get all shown data
chart.data.shown();
Get values of the data loaded in the chart.
.data.values(targetId)
targetId String
This API returns the values of specified target. If this argument is not given, null
will be retruned.
// Get data1 values
chart.data.values('data1');
Get and set names of the data loaded in the chart.
.data.names(names)
names Object
If this argument is given, the names of data will be updated. If not given, the current names will be returned. The format of this argument is the same as data.names.
// Get current names
chart.data.names();
// Update names
chart.data.names({
data1: 'New Name 1',
data2: 'New Name 2'
});
Get and set colors of the data loaded in the chart.
.data.colors(colors)
colors Object
If this argument is given, the colors of data will be updated. If not given, the current colors will be returned. The format of this argument is the same as data.colors.
// Get current colors
chart.data.colors();
// Update colors
chart.data.colors({
data1: '#FFFFFF',
data2: '#000000'
});
Get and set axes of the data loaded in the chart.
.data.axes(axes)
axes Object
If this argument is given, the axes of data will be updated. If not given, the current axes will be returned. The format of this argument is the same as data.axes.
// Get current axes
chart.data.axes();
// Update axes
chart.data.axes({
data1: 'y',
data2: 'y2'
});
Get and set x values for the chart.
.x(x)
x Array
If x is given, x values of every target will be updated. If no argument is given, current x values will be returned as an Object
whose keys are the target ids.
// Get current x values
chart.x();
// Update x values for all targets
chart.x([100, 200, 300, 400, ...]);
Get and set x values for the chart.
.xs(xs)
xs Object
If xs is given, specified target's x values will be updated. If no argument is given, current x values will be returned as an Object
whose keys are the target ids.
// Get current x values
chart.xs();
// Update x values for all targets
chart.xs({
data1: [10, 20, 30, 40, ...],
data2: [100, 200, 300, 400, ...]
});
Get and set axis labels.
.axis.labels(labels)
labels Object
If labels is given, specified axis' label will be updated.
// Update axis' label
chart.axis.labels({
x: 'New X Axis Label',
y: 'New Y Axis Label'
});
Get and set axis min value.
.axis.min(min)
min Object
If min is given, specified axis' min value will be updated. If no argument is given, the current min values for each axis will be returned.
// Update axis' min
chart.axis.min({
x: -10,
y: 1000,
y2: 100
});
Get and set axis max value.
.axis.max(max)
max Object
If max is given, specified axis' max value will be updated. If no argument is given, the current max values for each axis will be returned.
// Update axis' max
chart.axis.max({
x: 100,
y: 1000,
y2: 10000
});
Get and set axis min and max value.
.axis.range(range)
range Object
If range is given, specified axis' min and max value will be updated. If no argument is given, the current min and max values for each axis will be returned.
// Update axis' min and max values
chart.axis.range({
min: {
x: -10,
y: -1000,
y2: -10000
},
max: {
x: 100,
y: 1000,
y2: 10000
}
});
Show legend for each target.
.legend.show(targetIds)
targetIds Array
or String
If targetIds is given, specified target's legend will be shown. If only one target is the candidate, String
can be passed. If no argument is given, all of target's legend will be shown.
// Show legend for data1.
chart.legend.show('data1');
// Show legend for data1 and data2.
chart.legend.show(['data1', 'data2']);
// Show all legend.
chart.legend.show();
Hide legend for each target.
.legend.hide(targetIds)
targetIds Array
or String
If targetIds is given, specified target's legend will be hidden. If only one target is the candidate, String
can be passed. If no argument is given, all of target's legend will be hidden.
// Hide legend for data1.
chart.legend.hide('data1');
// Hide legend for data1 and data2.
chart.legend.hide(['data1', 'data2']);
// Hide all legend.
chart.legend.hide();
Zoom by giving x domain.
.zoom(domain)
domain Array
If domain is given, the chart will be zoomed to the given domain. If no argument is given, the current zoomed domain will be returned.
// Zoom to specified domain
chart.zoom([10, 20]);
// Get the current zoomed domain
chart.zoom();
Unzoom to the original domain.
.unzoom()
// Unzoom to the original domain
chart.unzoom();
Enable and disable zooming.
.zoom.enable(enabled)
enabled Boolean
If enabled is true
, the feature of zooming will be enabled. If false
is given, it will be disabled.
// Enable zooming
chart.zoom.enable(true);
Resize the chart.
.resize(size)
size Object
This argument should include width and height in pixels.
// Resize to 640x480
chart.resize({
height: 640,
width: 480
});
Force to redraw.
.flush()
// Force to redraw
chart.flush();
Reset the chart object and remove element and events completely.
.destroy()
// Destroy the chart
chart.destroy();
// If you have a reference to the chart make sure to call destroy in the following manner
chart = chart.destroy();
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...