dc.js Documentation

repository·develop·Indexed 27 days ago

https://github.com/dc-js/dc.js

A multi-dimensional charting library built to work natively with crossfilter for data management and rendered using d3.js. It enables the creation of interactive, linked charts where filtering one dimension dynamically updates all others. The library includes a variety of chart types such as BarChart, PieChart, LineChart, and ScatterPlot, as well as specialized widgets like DataCount, DataTable, and TextFilterWidget. Version 4.2.7 is compatible with d3 versions 4 and 5.

Tokens
104.5K
Snippets
259
Records
741
Agent score
89%

What's inside dc.js

  1. Overview of dc.js

    develop

    dc.js is a library for dimensional charting designed to work natively with crossfilter. It uses d3.js for rendering.

    Each chart in dc.js displays an aggregation of attributes through position, size, and color, and provides a dimension that can be filtered. When a filter or brush is applied, all other charts update dynamically using animated transitions.

  2. Understand dc.baseMixin

    develop
    dc.baseMixin is an abstract functional object that serves as the base for all chart and widget implementations in the dc library. All chart types inherit methods from baseMixin, providing core functionality such as dimension/group management, rendering, resizing, and filtering.
  3. BaseMixin: Abstract functional object for dc charts

    develop

    The BaseMixin is an abstract functional object that serves as the foundation for all chart and widget implementations in dc.js. All chart implementations inherit methods from BaseMixin, providing core functionality for dimensions, data, rendering, and resizing.

    Key inherited capabilities include:

    • Sizing: Control height, width, minHeight, minWidth, and useViewBoxResizing.
    • Data & Dimensions: Manage dimension (Crossfilter dimension), group (Crossfilter group), and data callbacks.
    • Rendering: Methods like render(), redraw(), renderGroup(), and resetSvg().
    • Filtering: Manage chart filters via filter(), replaceFilter(), filters(), and filterAll().
    • DOM/SVG: Access the chart's anchor, root, and svg elements.
  4. Use CoordinateGridMixin for coordinate-based charts

    develop
    The CoordinateGridMixin is an abstract base mixin used to create coordinate grid-based charts like bar, line, and bubble charts. It provides core functionality for managing scales, axes, zooming, and brushing. It mixes in ColorMixin and MarginMixin.
  5. Use the dc namespace and function chaining

    develop

    The entire dc.js library is scoped under the dc global namespace. Most dc functions support function chaining, where the function returns the current chart instance to allow multiple configuration calls in a single statement.

    Note that getter functions (functions used to retrieve values rather than set them) do not participate in chaining because they return the requested value instead of the chart instance. However, some getters like .svg() and .xAxis() return chainable d3 objects.

    // Example chaining
    chart.width(300)
         .height(300)
         .filter('sunday');
  6. Chain functions for chart configuration

    develop

    Most dc functions support method chaining. This allows you to configure a chart instance by calling multiple methods in a single sequence, as each method returns the current chart instance where appropriate.

    Note: The API documentation will specify if a particular function is not chainable.

    chart.width(300)
        .height(300)
        .filter("sunday")
  7. Upgrade from dc.js v3 to v4

    develop

    dc.js v4 is a major update that moves to ES6. Key implications include:

    • Browser Support: Internet Explorer is no longer supported. Use v3.x for legacy support.
    • Module System: The library is distributed as a UMD bundle, compatible with bundlers like Webpack and Rollup. If using as ES6 modules, you do not need to prefix classes and functions with dc.
    • Namespace: When using via a <script> tag in a browser, the library is exposed under the dc namespace.
    • Dependencies: dc no longer includes crossfilter2 as an npm dependency. dc.crossfilter is no longer exported; you must use crossfilter directly.