Chart

new Chart ( selection, chartOptions )

Create a d3.chart

You can edit the code in this block and rerun it.

Parameters

  • selection d3.selection required

    The chart's "base" DOM node. This should contain any nodes that the chart generates.

  • chartOptions mixed required

    A value for controlling how the chart should be created. This value will be forwarded to Chart#initialize, so charts may define additional properties for consumers to modify their behavior during initialization. The following attributes will be copied onto the chart instance (if present):

    Properties
    • transform function optional

      A data transformation function unique to the Chart instance being created. If specified, this function will be invoked after all inherited implementations as part of the Chart#draw operation.

    • demux function optional

      A data filtering function for attachment charts. If specified, this function will be invoked with every draw operation and provided with two arguments: the attachment name (see Chart#attach) and the data.

Source

Methods

<static> extend ( name, protoProps, staticProps )

Returns: function

Create a new Chart constructor with the provided options acting as "overrides" for the default chart instance methods. Allows for basic inheritance so that new chart constructors may be defined in terms of existing chart constructors. Based on the extend function defined by Backbone.js.

You can edit the code in this block and rerun it.

Parameters

  • name String required

    Identifier for the new Chart constructor.

  • protoProps Object required

    Properties to set on the new chart's prototype.

  • staticProps Object required

    Properties to set on the chart constructor itself.

Returns

A new Chart constructor

Type: function
Source

attach ( attachmentName, chart )

Returns: Chart

Register or retrieve an "attachment" Chart. The "attachment" chart's draw method will be invoked whenever the containing chart's draw method is invoked.

You can edit the code in this block and rerun it.

Parameters

  • attachmentName String required

    Name of the attachment

  • chart Chart optional

    d3.chart to register as a mix in of this chart. When unspecified, this method will return the attachment previously registered with the specified attachmentName (if any).

Returns

Reference to this chart (chainable).

Type: Chart
Source

draw ( data )

Update the chart's representation in the DOM, drawing all of its layers and any "attachment" charts (as attached via Chart#attach).

You can edit the code in this block and rerun it.

Parameters

  • data Object required

    Data to pass to the draw method of this cart's layers (if any) and the draw method of this chart's attachments (if any).

Source

initialize ( )

Set up a chart instance. This method is intended to be overridden by Charts authored with this library. It will be invoked with a single argument: the options value supplied to the constructor.

For charts that are defined as extensions of other charts using Chart.extend, each chart's initilize method will be invoked starting with the "oldest" ancestor (see the private initCascade function for more details).

Source

layer ( name, selection, options )

Returns: Layer

Interact with the chart's layers.

If only a name is provided, simply return the layer registered to that name (if any).

If a name and selection are provided, treat the selection as a previously-created layer and attach it to the chart with the specified name.

If all three arguments are specified, initialize a new Layer using the specified selection as a base passing along the specified options.

The Layer.draw method of attached layers will be invoked whenever this chart's Chart#draw is invoked and will receive the data (optionally modified by the chart's Chart#transform method.

You can edit the code in this block and rerun it.

Parameters

  • name String required

    Name of the layer to attach or retrieve.

  • selection d3.selection | Layer optional

    The layer's base or a previously-created Layer.

  • options Object optional

    Options to be forwarded to the Layer constructor

Returns

Type: Layer
Source

off ( name, callback, context )

Returns: Chart

Unsubscribe one or more callback functions from an event triggered on the chart. When no arguments are specified, all handlers will be unsubscribed. When only a name is specified, all handlers subscribed to that event will be unsubscribed. When a name and callback are specified, only that function will be unsubscribed from that event. When a name and context are specified (but callback is omitted), all events bound to the given event with the given context will be unsubscribed.

You can edit the code in this block and rerun it.

Parameters

  • name String optional

    Name of the event to be unsubscribed

  • callback ChartEventHandler optional

    Function to be unsubscribed

  • context Object optional

    Contexts to be unsubscribe

Returns

A reference to this chart (chainable).

Type: Chart
Source

on ( name, callback, context )

Returns: Chart

Subscribe a callback function to an event triggered on the chart. See Chart#once to subscribe a callback function to an event for one occurence.

You can edit the code in this block and rerun it.

Parameters

  • name String required

    Name of the event

  • callback ChartEventHandler required

    Function to be invoked when the event occurs

  • context Object optional

    Value to set as this when invoking the callback. Defaults to the chart instance.

Returns

A reference to this chart (chainable).

Type: Chart
Source

once ( name, callback, context )

Returns: Chart

Subscribe a callback function to an event triggered on the chart. This function will be invoked at the next occurance of the event and immediately unsubscribed. See Chart#on to subscribe a callback function to an event indefinitely.

You can edit the code in this block and rerun it.

Parameters

  • name String required

    Name of the event

  • callback ChartEventHandler required

    Function to be invoked when the event occurs

  • context Object optional

    Value to set as this when invoking the callback. Defaults to the chart instance

Returns

A reference to this chart (chainable)

Type: Chart
Source

transform ( data )

Returns: mixed

A "hook" method that you may define to modify input data before it is used to draw the chart's layers and attachments. This method will be used by all sub-classes (see transformCascade for details).

Note you will most likely never call this method directly, but rather include it as part of a chart definition, and then rely on d3.chart to invoke it when you draw the chart with Chart#draw.

You can edit the code in this block and rerun it.

Parameters

  • data Array required

    Input data provided to @link Chart#draw}.

Returns

Data to be used in drawing the chart's layers and attachments.

Type: mixed
Source

trigger ( name, arguments )

Returns: Chart

Publish an event on this chart with the given name.

You can edit the code in this block and rerun it.

Parameters

  • name String required

    Name of the event to publish

  • arguments * required <repeatable>

    Values with which to invoke the registered callbacks.

Returns

A reference to this chart (chainable).

Type: Chart
Source

unlayer ( name )

Returns: Layer

Remove a layer from the chart.

You can edit the code in this block and rerun it.

Parameters

  • name String required

    The name of the layer to remove.

Returns

The layer removed by this operation.

Type: Layer
Source