Chapter 12. Creating Charts for the Web

In this chapter, we will cover the following recipes:

  • Serving data with Ring and Compojure
  • Creating HTML with Hiccup
  • Setting up to use ClojureScript
  • Creating scatter plots with NVD3
  • Creating bar charts with NVD3
  • Creating histograms with NVD3
  • Creating time series charts with D3
  • Visualizing graphs with force-directed layouts
  • Creating interactive visualizations with D3

Introduction

In the previous chapter, we explored how to create graphs in order to publish in print or online by creating PNGs. Of course, the Internet can do a lot more than publish static images. Much of the power of the Internet lies in the fact that it's interactive. Adding rich data visualizations to the web's interactions makes a powerful environment in which you can explore and gain insights into the questions you're researching. In this chapter, we'll explore how to create a full web application using Clojure, including interactive graphs.

First, we'll set up a web application with Ring (https://github.com/ring-clojure/ring) and Compojure (http://compojure.org). Ring is an interface between web servers and web applications. Compojure is a small web framework that provides a convenient way to define and handle routes (the associations between URLs and functions to provide data for them).

Next, we'll see how to use Hiccup (https://github.com/weavejester/hiccup) in order to generate HTML from data structures.

We'll complete our web stack with ClojureScript (https://github.com/clojure/clojurescript). This is just Clojure, but instead of compiling to a JVM, it compiles to JavaScript. We can load its output into our web pages and use it to create stunning graphs.

The rest of the chapter will involve what we can create using this Clojure-dominated web stack. We'll use the D3 (http://d3js.org/) and NVD3 (http://nvd3.org/) JavaScript libraries to create visualizations from the data. In the end, we'll wind up with some good graphs and a productive environment to publish the results of our data analysis.

The stack from this chapter can be easily deployed to services such as Heroku (http://www.heroku.com/), which makes for a fast way to set up the server side of this system and to make our information available to the general public.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.145.82