The D3.js module provides better integration for Drupal and the D3.js - Data-Driven Documents visualization library.

There are three major ways to integrate Drupal and D3:

  • basic views integration
  • views integration with custom D3 library
  • custom D3 library with direct calls to database or other way of adding data (headless Drupal :) )

There is no direct upgrade from the version of the module before April 2015 release.

Installation

  1. Install module via web interface, drush or upload and enable d3 modules
  2. Upload d3 library into folder sites/all/libraries/d3. Source libraries are in https://github.com/mbostock/d3, you can use d3 or d3.min or get version 3 http://d3js.org/d3.v3.js. Although READEME says to use latest version of D3, many have found that using version works best, especially for the examples module.
  3. After these steps you should be able to see examples at url d3/examples

Configuring views to work with existing libraries

If you want to use d3 to display your data, you first need to configure data in the way that is consistent with provided types of charts.

Configuring column chart

View this Google Presentation for step by step configuration.

Other video documentation

  • old videos do not apply anymore


Upgrading from 7.x-1.x-dev to 7.x-1.0-alpha1 version

Version 7.x-1.0-alpha1 has changes in d3 views interface configuration and in .info file for a custom library

Changes to .info file

  • line "views = 3.0" has to be added to
  • mapping for fields is not required anymore in .info file and is now done through interface interface for mapping fields
  • you can use numeric array or associative array by adding line

    views[fields][rows][__data_type] = 2dnav ; for associative

    views[fields][rows][__data_type] = 2dnnv ; for numeric

    details are described in file sites/all/modules/d3/modules/d3_views/ d3_views.api.php

AttachmentSize
Interface for mapping fields106.57 KB

Comments

nithinkolekar’s picture

some clarification needed

mapping for fields is not required anymore in .info file and is now done through interface

If there is no mapping in .info file of custom library then view mapping form don't show up.

From d3_views.api.php

* - 1dn:   1-dimensional numeric array of fields / labels
 * array('field value 1', 'field value 2', 'field value 3')
 * - 1dnv:  1-dimensional numeric array of row values 
 * array('field row value 1', 'field row value 2', 'field row value 3')
 * - 1da:   1-dimensional associative array of fields / labels
 * array(
 *  'fieldValue1' => 'field value 1',
 *  'fieldValue2' => 'field value 2',
 *  'fieldValue3' => 'field value 3',
 * )

what is the difference between "field value1" of 1dn vs "field row value 1" of 1dnv in views rows perspective? when should we use those different _data_type?
there is no definition for functions map1DNV($row) , map1DA($row) . Do you Forgot to push code to repository?

From d3.linegraph.libraries.info (related to label)

views[fields][legend][__cardinality] = 0
views[fields][legend][__data_type] = 1dn
views[fields][legend][label] = Line label
views[fields][legend][description] = The meaning of each different line.

what do you mean by each different line, could we make multi-line chart from the views tabular data? I tried creating one but when checks the code for map1DN in D3ViewsDataMapping.inc it is mapping label. Shouldn't it be field value instead?

brechacik’s picture

Example of d3 Force directed graph using Drupal 7 with relation module, graph api and views:

https://jsfiddle.net/svorad/ecwryk58/