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. |
axis․max(max)
- Source:
Get and set axis max value.
Example
// Update axis' label
chart.axis.max({
x: 100,
y: 1000,
y2: 10000
});
Parameters:
Name | Type | Description |
---|---|---|
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. |
axis․min(min)
- Source:
Get and set axis min value.
Example
// Update axis' min
chart.axis.min({
x: -10,
y: 1000,
y2: 100
});
Parameters:
Name | Type | Description |
---|---|---|
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. |
axis․range(range)
- Source:
Get and set axis min and max value.
Example
// Update axis' label
chart.axis.range({
min: {
x: -10,
y: -1000,
y2: -10000
},
max: {
x: 100,
y: 1000,
y2: 10000
},
});
Parameters:
Name | Type | Description |
---|---|---|
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. |
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․axes(axes)
- Source:
Get and set axes of the data loaded in the chart.
Example
// Get current axes
chart.data.axes();
// Update axes
chart.data.axes({
data1: "y",
data2: "y2"
});
Parameters:
Name | Type | Description |
---|---|---|
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․colors(colors)
- Source:
Get and set colors of the data loaded in the chart.
Example
// Get current colors
chart.data.colors();
// Update colors
chart.data.colors({
data1: "#FFFFFF",
data2: "#000000"
});
Parameters:
Name | Type | Description |
---|---|---|
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․names(names)
- Source:
Get and set names of the data loaded in the chart.
Example
// Get current names
chart.data.names();
// Update names
chart.data.names({
data1: "New Name 1",
data2: "New Name 2"
});
Parameters:
Name | Type | Description |
---|---|---|
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․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. |
data․values(targetIds)
- Source:
Get values of the data loaded in the chart.
Example
// Get data1 values
chart.data.values("data1");
Parameters:
Name | Type | Description |
---|---|---|
targetIds |
String | Array | This API returns the values of specified target. If this argument is not given, null will be retruned |
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();
export(mimeTypeopt, callbackopt) → {String}
- Source:
Export chart as an image.
- NOTE: IE11 and below not work properly due to the lack of the feature(foreignObject) support
Example
chart.export();
// --> "data:image/svg+xml;base64,PHN..."
// Initialize the download automatically
chart.export("image/png", dataUrl => {
const link = document.createElement("a");
link.download = `${Date.now()}.png`;
link.href = dataUrl;
link.innerHTML = "Download chart as image";
document.body.appendChild(link);
});
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
mimeType |
String |
<optional> |
image/png
|
The desired output image format. (ex. 'image/png' for png, 'image/jpeg' for jpeg format) |
callback |
function |
<optional> |
The callback to be invoked when export is ready. |
Returns:
dataURI
- Type
- String
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․hide(targetIds)
- Source:
Hide legend for each target.
Example
// 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();
Parameters:
Name | Type | Description |
---|---|---|
targetIds |
String | Array |
|
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"],
url: "...",
done: function() { ... }
});
Parameters:
Name | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Object | The object can consist with following members:
|
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
regions․remove(regions) → {Array}
- Source:
Remove regions.
This API removes regions.
Example
// 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();
Parameters:
Name | Type | Description |
---|---|---|
regions |
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. |
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․hide()
- Source:
Hide tooltip
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. |
xgrids․remove(params)
- Source:
Remove x grid lines.
This API removes x grid lines.
Example
// 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();
Parameters:
Name | Type | Description |
---|---|---|
params |
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. |
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. |
ygrids․remove(params)
- Source:
Remove y grid lines.
This API removes x grid lines.
Example
// 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();
Parameters:
Name | Type | Description |
---|---|---|
params |
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. |
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. |
zoom․max(max)
- Source:
Set zoom max
Parameters:
Name | Type | Description |
---|---|---|
max |
Number |
zoom․min(min)
- Source:
Set zoom min
Parameters:
Name | Type | Description |
---|---|---|
min |
Number |
zoom․range(range) → {Object}
- Source:
Set zoom range
Example
chart.zoom.range({
min: 10,
max: 100
});
Parameters:
Name | Type | Description |
---|---|---|
range |
Object |
Returns:
range { min: 0, max: 100 }
- Type
- Object