Highcharts Demo

author(s): Torstein Hønsi

by easter bunny

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="container"></div>

CSS

#container {
	max-width: 660px;
	margin: auto;
	height: 400px;
	margin: 0 auto;
}

JavaScript

var colors = Highcharts.getOptions().colors,
    categories = [
        "Male",
        "Female"
    ],
    data = [
        {
            "y": 50,
            "color": colors[0],
            "drilldown": {
                "name": "Male",
                "categories": [
                    "Age : 1-18",
                    "Age : 19-30",
                    "Age : 31-50",
                    "Age : 51-70"
                ],
                "data": [
                    10,
                    30,
                    6,
                    4
                ]
            }
        },
        {
            "y": 50,
            "color": colors[1],
            "drilldown": {
                "name": "Female",
                "categories": [
                    "Age : 1-18",
                    "Age : 19-30",
                    "Age : 31-50",
                    "Age : 51-70"
                ],
                "data": [
                    10,
                    30,
                    6,
                    4
                ]
            }
        },
       
    ],
    browserData = [],
    versionsData = [],
    i,
    j,
    dataLen = data.length,
    drillDataLen,
    brightness;


// Build the data arrays
for (i = 0; i < dataLen; i += 1) {

    // add browser data
    browserData.push({
        name: categories[i],
        y: data[i].y,
        color: data[i].color
    });

    // add version data
    drillDataLen = data[i].drilldown.data.length;
    for (j = 0; j < drillDataLen; j += 1) {
        brightness = 0.2 - (j / drillDataLen) / 5;
        versionsData.push({
            name: data[i].drilldown.categories[j],
            y: data[i].drilldown.data[j],
            color: Highcharts.Color(data[i].color).brighten(brightness).get()
        });
    }
}

// Create the chart
Highcharts.chart('container', {
    chart: {
        type: 'pie'
    },
    title: {
        text: 'Age-Demographic Relationship Chart'
    },
    subtitle: {
        text: 'Last 3 Months...