-
Notifications
You must be signed in to change notification settings - Fork 83
Irene Ros edited this page Apr 16, 2013
·
22 revisions
#### `d3.chart(name, options)`
Description:
Used to define a new chart type.
Parameters:
-
name- the name of the chart one wishes to create. This is the generic 'type' of chart you're creating, for example 'barchart' rather than an instance of a chart that you're initializing. -
options- the methods that will be available to the chart instance. See creating for more information on defining a chart.
Uses:
Example chart creation:
d3.chart('MyChartType', {
initialize: function() {
}
// any additional instance methods go here.
});#### `.chart(name)`
Description:
Used to create a chart instance on a selection or retrieve the chart reference within a layer.
Parameters:
-
name- the name of the chart one wishes to use. Optional.
Uses:
There are two types of uses for the .chart method when called on a selection:
- To initialize a chart from a selection. For example:
var chart = d3.select("div#vis")
.append("svg")
.attr("width", 200)
.attr("height", 200)
.chart("BarChart"); // assuming we've defined a BarChart chart type.- To retrieve the chart associated with a layer from within the layer methods:
// from within a chart definition:
chart.layer({
dataBind: function(data) {
var chartInstance = this.chart();
}
});Note you can only retrieve the chart from the layer, not from any selection that could possibly live within a chart's DOM tree.