21

Is there any Canvas library that is like d3.js (is svg library). I have a website here and I coded a graph with svg elements however it is not efficient on smart phone's browsers and works so slow. I now, want to change it with a 2d canvas type of it and see whether it is better or not. Can you suggest a canvas library that is useful for this purpose?

Thanks...

Eren Golge
  • 802
  • 2
  • 12
  • 27

5 Answers5

23

D3 is not necessarily an svg only library - svg is used in many cases, but the library can do any kind of representations that you would like to make. See this example of parallel coordinates using canvas in D3, by Kai Chang: http://bl.ocks.org/2409451

Also see here for some discussion on performance issues, etc, that might be helpful: https://groups.google.com/d/topic/d3-js/mtlTsGCULVQ/discussion

Josh
  • 5,460
  • 31
  • 38
  • is there any performance comparison of SVG vs CANVAS? it seems canvas are much better but there is not much canvas centric libs for data visualization like D3 does for svg – Phyo Arkar Lwin Nov 20 '12 at 17:08
  • 2
    @V3ss0n: For a SVG vs canvas comparison, take a look at the comparison provided on [OpenLayers website](http://trac.osgeo.org/openlayers/wiki/Future/OpenLayersWithCanvas). – amergin Dec 05 '12 at 16:13
  • 1
    @V3ss0n: See http://citeseerx.ist.psu.edu/viewdoc/download?rep=rep1&type=pdf&doi=10.1.1.141.7632 – Robin Wieruch Mar 12 '14 at 13:00
8

I know I am late to the party, but times have changed, and I believe this question deserves an updated answer. SVG performance has improved a lot over the years and especially for the non-trivial graph-like visualizations it often gives superior performance; but it really depends on the exact use-case: If the visualization is simple and consists of thousands of elements, especially on mobile, Canvas may be the faster option. If the visualization is almost trivial, WebGL gives the best performance and beats Canvas hands-down - especially on mobile!

However WebGL especially and also Canvas are a bit harder to use than the declarative approach that SVG uses. Things like CSS animations and transitions are easy to do with SVG and give good performance due to being hardware accelerated and totally independent of JavaScript performance. Canvas and WebGL always require JavaScript.

If you take a look at the commercial graph drawing library yFiles for HTML you will see that it offers all three technologies at the same time. This is because all three can be the best choice, depending on the exact use-case.

There is a blog entry that compares the performance of SVG, Canvas, and WebGL especially in the context of graph visualization. It compares various graph sizes and categories of devices. The "conclusion" is that there is not a clear winner. Often times the combination of all three technologies gives the best results. For smaller graphs, though, SVG most of the time gives very good results and is a pleasure to work with. That's also the reason why d3.js has its focus on SVG, rather than Canvas and WebGL, I would say.

There is an interactive demo linked from that blog entry that let's you play with the various technologies and see their strengths and weaknesses. Of course the demo mainly compares the three technologies used in that specific library so your results may vary, but they spent a lot of time optimizing all three technologies in that library, so I think the results are not too biased.

Disclaimer: I work for the company that creates the above mentioned library, but I do not represent my employer here on SO. I think what I said should be valid not just for that library.

Sebastian
  • 7,729
  • 2
  • 37
  • 69
6

For the Samsung Olympic Genome Project facebook app, we used http://thejit.org to make the force directed graph style animation for the app. It's heavily modified by me and others on my team of course, and only plays a very small part in the app, but it's quite a powerful framework.

jaredwilli
  • 11,762
  • 6
  • 42
  • 41
5

Chart.js is a javascript library that just came out that creates charts using HTML5 for rendering. Its not as feature inclusive as D3, but it is working to become exactly that in the future. http://www.chartjs.org/

C Ried
  • 290
  • 4
  • 15
4

Take a look at Cytoscape.JS which uses a HTML5 canvas for rendering. At the time of writing this it's in its infancy but the project seems promising. According to its wiki the library supports both desktop and mobile browsers:

Cytoscape.js is easily integrated into your webapp, especially since Cytoscape.js supports both desktop browsers, like Chrome, and mobile browsers, like on the iPad.

amergin
  • 962
  • 1
  • 12
  • 32
  • 1
    Nice use of various canvas layers to optimize user interaction redraws! Impressed. – Joseph Lust Apr 30 '13 at 20:21
  • Dude, thanks a lot for mentioning this. I've gone through a whole heap of JS libraries today, including D3, JIT, Arbor, Sigma and whatnot, and they are all either insane (D3) or totaly inflexible (JIT,...). This looks like it could save my day. – kralyk Dec 30 '13 at 01:13