Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3 dimension (X, Y and Z) graph using D3.js [closed]

I am searching for a graph which has 3 dimensions (x, y, and z) and uses D3.js. Please let me know if there are any data visualization site where I can find such graph or if there is one on d3js.org that I have missed out somehow.

like image 948
Kish Avatar asked Jan 10 '14 11:01

Kish


People also ask

What is the syntax to draw a line in D3?

To make a line, we will use the line generator of d3 by invoking d3. line() . This line generator can then be used to compute the d attribute of an SVG path element. We append path to our SVG and then specify the class as line .

What is D3 js axis component?

Advertisements. D3 provides functions to draw axes. An axis is made of Lines, Ticks and Labels. An axis uses a Scale, so each axis will need to be given a scale to work with.

Which is D3 component function?

A D3 component, like an axis, is a function for drawing all the graphical elements necessary for an axis. A generator, like d3. line() , lets you draw a straight or curved line across many points.

How do I create a circle in JavaScript D3?

Adding a circle with append("circle") Three arguments are required: cx , cy and r for x position, y position and radius respectively.


2 Answers

The 3D scatterplot linked to by VividD and Lars Kotthoff is probably the best example of what you're asking for, but I'm going to be contrary and suggest that maybe you're asking the wrong question.

Trying to simulate three spatial dimensions on a flat screen will always be imperfect and make it difficult to read the data. However, it is very easy to graph three different data dimensions in D3. You use the horizontal and vertical layouts for two of your data variables, and then size, shape, color or shading for your third variable.

If all three of your data variables are best represented by continuous numbers, then your best approach is to use a bubble-scatterplot, where your three display dimensions are horizontal positions, vertical position, and bubble size.

Here's an example the also uses the online interactive component to add a fourth dimension shown via motion:
Bubble ScatterplotBubble Scatterplot -- click for original

You said that your three dimensions are Customer, Product and content. I don't know what kind of value "content" is (number or category), but I'm pretty sure that "customer" and "product" are categories.

Here's an example where two categorical dimensions are used to lay out a table, then each cell of the table contains a circle sized by the third, numerical dimension. If your third variable is a category, you could use a shape to indicate which "content" type (if any) goes with each pairing of "customer" and "product":
Bubble Matrix
(source: fastly.net)

Bubble Matrix -- click for original](http://neuralengr.com/asifr/journals/)

Here's another one, where the third dimension is shown by colour instead of by size. The colours represent a continuous variable, but you could easily choose a set of high-contrast colours to represent categories:
Colour MatrixColour Matrix -- click for original

Of course, a plain-old stacked bar chart is another way to show two categories and a numerical quantity:
Stacked Bar Graphs Stacked Bar Graphs -- click for original

And you don't have to stop at three data variables. If two of the data variables are either categories or numbers that you don't mind grouping into categories, you can graph four variables with a "small multiple" approach, where you create a table representing the categorical variables and then repeat a graph of the other two variables inside each table cell.

Like this:
Scatterplot MatrixScatterplot Matrix -- click for original

Or this (where week and day-of-week are two dimensions of the data, and category/amount are the other two):
Pie Chart Small Multiples
Pie Chart Small Multiples -- click for original

I hope that gave you lots of ideas...

like image 119
AmeliaBR Avatar answered Sep 23 '22 04:09

AmeliaBR


One example that a kind of resembles what you seek is:

3D scatter plot

enter image description here

Be aware that this example uses X3DOM, a fairly new attempt to standardize 3D rendering in HTML, that is not supported by all browsers.


Some additional test examples on using D3.js with X3DOM:

X3DOM in callback test

D3 X3DOM event test

Search also for X3DOM on D3 Google group.


Another potentially interesting approach would be using D3.js and Three.js, like here:

Showing GPS tracks in 3D with three.js and d3.js


In general, D3.js is oriented more towards data visualization than scientific visualization, this means it doesn't have extensive support for displaying 3D space (with an exception of displaying geographic 3D data, which D3.js supports in an excellent way, but this is not what need).

For example (this example is not related directly to your examples, it's just for explanation): D3 provides algorithm for 2D drawing of trees, but doesn't provide any apparatus for 3D placement of trees and subsequent rendering such placement on a 2D screen.


If you are not limited to D3.js, perhaps you could achieve same goals easier and faster with other libraries, written specifically for purposes similar to yours. For example, you can use Pre3D. Take a look at this example. Pre3D doesn't use X3DOM, just plain HTML rendering on 2D canvas. I think it animation (rotation) of its 3D graphs are smoother that those in first D3/X3DOM example.

like image 44
VividD Avatar answered Sep 22 '22 04:09

VividD