new Chart()
- Source:
- See:
-
- bb.generate for the initialization.
Main chart class.
- Note: Instantiated via
bb.generate()
.
Example
var chart = bb.generate({
data: {
columns: [
["x", "2015-11-02", "2015-12-01", "2016-01-01", "2016-02-01", "2016-03-01"],
["count1", 11, 8, 7, 6, 5 ],
["count2", 9, 3, 6, 2, 8 ]
]}
}
Methods
axis:labels(labels)
- Source:
Get and set axis labels.
Example
// Update axis' label
chart.axis.labels({
x: "New X Axis Label",
y: "New Y Axis Label"
});
Parameters:
Name | Type | Description |
---|---|---|
labels |
Object | specified axis' label to be updated. |
categories(categories)
- Source:
Set category names on category axis.
Example
chart.categories([
"Category 1", "Category 2", ...
]);
Parameters:
Name | Type | Description |
---|---|---|
categories |
Array | 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. |
category(i, category)
- Source:
Set specified category name on category axis.
Example
chart.category(2, "Category 3");
Parameters:
Name | Type | Description |
---|---|---|
i |
Number | index of category to be changed |
category |
String | category value to be changed |
color(id)
- Source:
Get the color
Example
chart.color("data1");
Parameters:
Name | Type | Description |
---|---|---|
id |
String | id to get the color |
data(targetIds)
- Source:
Get data loaded in the chart.
Example
// Get only data1 data
chart.data("data1");
// Get data1 and data2 data
chart.data(["data1", "data2"]);
// Get all data
chart.data();
Parameters:
Name | Type | Description |
---|---|---|
targetIds |
String | 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. |
data:shown(targetIds)
- Source:
Get data shown in the chart.
Example
// 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();
Parameters:
Name | Type | Description |
---|---|---|
targetIds |
String | 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. |
defocus(Target)
- Source:
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.
Example
// 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();
Parameters:
Name | Type | Description |
---|---|---|
Target |
String | Array | ids to be faded out. |
destroy()
- Source:
Reset the chart object and remove element and events completely.
Example
chart.destroy();
flow(args)
- Source:
Flow data to the chart.
By this API, you can append new data points to the chart.
Example
// 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
});
}
});
Parameters:
Name | Type | Description |
---|---|---|
args |
Object |
|
flush()
- Source:
Force to redraw.
Example
chart.flush();
focus(targetIdsValue)
- Source:
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.
Example
// 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();
Parameters:
Name | Type | Description |
---|---|---|
targetIdsValue |
String | Array | Target ids to be highlighted. |
groups(groups)
- Source:
Update groups for the targets.
Example
// data1 and data2 will be a new group.
chart.groups([
["data1", "data2"]
]);
Parameters:
Name | Type | Description |
---|---|---|
groups |
Array | This argument needs to be an Array that includes one or more Array that includes target ids to be grouped. |
hide(targetIdsValue, options)
- Source:
Hide data points
Parameters:
Name | Type | Description |
---|---|---|
targetIdsValue |
String | Array | |
options |
Object |
legend:show(targetIds)
- Source:
Show legend for each target.
Example
// 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();
Parameters:
Name | Type | Description |
---|---|---|
targetIds |
String | Array |
|
load(args)
- Source:
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.
- Note:
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
Example
// Load data1 and unload data2 and data3
chart.load({
columns: [
["data1", 100, 200, 150, ...],
...
],
unload: ["data2", "data3"]
});
Parameters:
Name | Type | Description |
---|---|---|
args |
Object |
|
regions(regions) → {Array}
- Source:
Update regions.
Example
// Show 2 regions
chart.regions([
{axis: "x", start: 5, class: "regionX"},
{axis: "y", end: 50, class: "regionY"}
]);
Parameters:
Name | Type | Description |
---|---|---|
regions |
Array | Regions will be replaced with this argument. The format of this argument is the same as regions. |
Returns:
regions
- Type
- Array
regions:add(regions) → {Array}
- Source:
Add new region.
This API adds new region instead of replacing like regions.
Example
// 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"}
]);
Parameters:
Name | Type | Description |
---|---|---|
regions |
Array | 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. |
Returns:
regions
- Type
- Array
resize(size)
- Source:
Resize the chart.
Example
// Resize to 640x480
chart.resize({
width: 640,
height: 480
});
Parameters:
Name | Type | Description |
---|---|---|
size |
Object | This argument should include width and height in pixels. |
revert(Target)
- Source:
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.
Example
// data1 will be reverted.
chart.revert("data1");
// data1 and data2 will be reverted.
chart.revert(["data1", "data2"]);
// all targets will be reverted.
chart.revert();
Parameters:
Name | Type | Description |
---|---|---|
Target |
String | Array | ids to be reverted |
select(ids, indices, resetOther)
- Source:
Set data points to be selected.
Example
// select from 'data1', indices 2 and unselect others selected
chart.select("data1", 2, true);
Parameters:
Name | Type | Description |
---|---|---|
ids |
String | |
indices |
Number | |
resetOther |
Boolean |
selected(targetId) → {Array}
- Source:
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.
Example
// all selected data points will be returned.
chart.selected();
// all selected data points of data1 will be returned.
chart.selected("data1");
Parameters:
Name | Type | Description |
---|---|---|
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. |
Returns:
dataPoint
- Type
- Array
show(targetIdsValue, options)
- Source:
Show data points
Parameters:
Name | Type | Description |
---|---|---|
targetIdsValue |
String | Array | |
options |
Object |
toggle(targetIds, options)
- Source:
Toggle data points
Parameters:
Name | Type | Description |
---|---|---|
targetIds |
Array | |
options |
Object |
tooltip:show(args)
- Source:
Show tooltip
Parameters:
Name | Type | Description |
---|---|---|
args |
Array |
transform(type, targetIds)
- Source:
Change the type of the chart.
Example
// 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"]);
Parameters:
Name | Type | Description |
---|---|---|
type |
String | Specify the type to be transformed. The types listed in data.type can be used. |
targetIds |
String | Array | Specify targets to be transformed. If not given, all targets will be the candidate. |
unload(args)
- Source:
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.
- Note:
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.
Example
// Unload data2 and data3
chart.unload({
ids: ["data2", "data3"]
});
Parameters:
Name | Type | Description |
---|---|---|
args |
Object |
|
unselect(ids, indices)
- Source:
Set data points to be un-selected.
Example
// unselect from 'data1', indices 2
chart.unselect("data1", 2);
Parameters:
Name | Type | Description |
---|---|---|
ids |
String | |
indices |
Number |
unzoom()
- Source:
Unzoom zoomed area
Example
chart.unzoom();
x(x) → {Object}
- Source:
Get and set x values for the chart.
Example
// Get current x values
chart.x();
// Update x values for all targets
chart.x([100, 200, 300, 400, ...]);
Parameters:
Name | Type | Description |
---|---|---|
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. |
Returns:
xs
- Type
- Object
xgrids(grids)
- Source:
Update x grid lines.
Example
// Show 2 x grid lines
chart.xgrids([
{value: 1, text: "Label 1"},
{value: 4, text: "Label 4"}
]);
Parameters:
Name | Type | Description |
---|---|---|
grids |
Array | X grid lines will be replaced with this argument. The format of this argument is the same as grid.x.lines. |
xgrids:add(grids)
- Source:
Add x grid lines.
This API adds new x grid lines instead of replacing like xgrids.
Example
// 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"}
]);
Parameters:
Name | Type | Description |
---|---|---|
grids |
Array | 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. |
xs(xs) → {Object}
- Source:
Get and set x values for the chart.
Example
// Get current x values
chart.xs();
// Update x values for all targets
chart.xs({
data1: [10, 20, 30, 40, ...],
data2: [100, 200, 300, 400, ...]
});
Parameters:
Name | Type | Description |
---|---|---|
xs |
Array | 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. |
Returns:
xs
- Type
- Object
ygrids(grids)
- Source:
Update y grid lines.
Example
// Show 2 y grid lines
chart.ygrids([
{value: 100, text: "Label 1"},
{value: 400, text: "Label 4"}
]);
Parameters:
Name | Type | Description |
---|---|---|
grids |
Array | Y grid lines will be replaced with this argument. The format of this argument is the same as grid.y.lines. |
ygrids:add(grids)
- Source:
Add y grid lines.
This API adds new y grid lines instead of replacing like ygrids.
Example
// Add a new x grid line
chart.ygrids.add(
{value: 400, text: "Label 4"}
);
// Add new x grid lines
chart.ygrids.add([
{value: 200, text: "Label 2"},
{value: 400, text: "Label 4"}
]);
Parameters:
Name | Type | Description |
---|---|---|
grids |
Array | 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. |
zoom(domainValue)
- Source:
Zoom by giving x domain.
Example
// Zoom to specified domain
chart.zoom([10, 20]);
// Get the current zoomed domain
chart.zoom();
Parameters:
Name | Type | Description |
---|---|---|
domainValue |
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:enable(enabled)
- Source:
Enable and disable zooming.
Example
// Enable zooming
chart.zoom.enable(true);
Parameters:
Name | Type | Description |
---|---|---|
enabled |
Boolean | If enabled is true, the feature of zooming will be enabled. If false is given, it will be disabled. |