Book Image

Highcharts Cookbook

By : Nicholas Terwoord
Book Image

Highcharts Cookbook

By: Nicholas Terwoord

Overview of this book

<p>Highcharts is a JavaScript library that enables web developers to create a wide range of different, highly customized charts. Highcharts easily integrates with existing JavaScript frameworks and is simple enough to make a column chart in a few lines of code, but flexible enough to handle more complex charting scenarios such as viewing multiple chart types with different data sources on a multitude of devices and form-factors.</p> <p>"Highcharts Cookbook" is a practical guide that provides you with clear, step-by-step recipes to create dynamic, functional charts in your web applications using Highcharts. With "Highcharts Cookbook", you will create and design dynamic and versatile charts in different scenarios.</p> <p>"Highcharts Cookbook" through its wide array of recipes will walk you through everything you need to know about Highcharts and will enable you to unleash its full potential in your web applications quickly and easily.</p> <p>You will learn how to integrate Highcharts with different frontend and backend libraries such as ExtJS, jQuery, and the Yii framework with some examples in Python, PHP, and NodeJS. You will also cover how to handle user interactions like form input and mouse events, how to fetch remote data in CSV, XML, and JSON format, and how to render charts for offline usage. If you want to learn the different ways you can leverage the power of Highcharts to create, integrate and extend its features in your application, then this book is for you.</p>
Table of Contents (19 chapters)
Highcharts Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating spiderweb graphs for comparison


We like to compare different things, but sometimes, the things that we want to compare differ in more than just one or two axes. Rather than displaying multiple graphs, we can amalgamate these different axes into one graph and use the spiderweb graph.

How to do it...

To get started, follow the ensuing instructions:

  1. Define options for our basic chart, setting the polar property of the chart to true using the following code:

    var options = {
        chart: {
            polar: true,
            type: 'line'
        },
        title: {
            text: 'Creating spiderweb graphs for comparison'
        }
    }

    Note

    To create a spiderweb graph, we'll need to make a polar chart. The previous options will change our display from an ordinary two-axes chart into an arbitrary-axes chart that is more like a circle.

  2. Label the axes of our graph by setting xAxis.categories, as shown in the following code:

    options= {
        // ...
        xAxis: {
            categories: ["Strength", "Speed", "Defense"],
            tickmarkPlacement: 'on'
        }
    };
  3. Set yAxis.gridLineInterpolation to polygon to make the chart less rounded, as shown in the following code:

    var options= {
        // ...
        yAxis: {
            gridLineInterpolation: 'polygon'
        }
    };
  4. Define the data for our spiderweb graph as follows:

    var options = {
        // ...
        series: [{
            name: 'Fighter',
            data: [10, 1, 5],
            pointPlacement: 'on'
        }, {
            name: 'Rogue',
            data: [5, 10, 1],
            pointPlacement: 'on'
        }]
    };

    The following is the rendered graph: