Chapter 4: Introducing Bar Charts (2)

Top 10 countries with patents granted in bar chart. Horizontal x-axis label, data label inside bars

HTML

<script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>
<body>
<div style="margin: 5px 60px 5px 5px; " id='container'></div>
</body>

JavaScript

$(document).ready(function() {
        var chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'column',
                borderWidth: 1,
                inverted: false
            },
            title: {
                text: 'Number of Patents Granted in 2011'
            },
            credits: { 
               position: {
                  align: 'left',
                  x: 20
               },
               href: 'http://www.uspto.gov',
               text: 'Source: U.S. Patent & Trademark Office'
            },
            xAxis: {
                categories: [ 'United States', 'Japan', 'South Korea', 'Germany', 'Taiwan', 
                              'Canada', 'France', 'United Kingdom', 'China', 'Italy' ]
            },
            yAxis: {
                title: {
                    text: 'No. of Patents'
                },
                labels: {
                    rotation: -45,
                    align: 'right'
                },
                type: 'logarithmic'
            },
            plotOptions: {
                column: {
                    colorByPoint: true,
                    dataLabels: {
                        enabled: true,
                        color: '#F4F4F4',
                        x: -50,
                        y: 0,
                        formatter: function() {
                            return Highcharts.numberFormat(this.y, 0);
                        },
                        style: {
                            fontWeight: 'bold'
                        }
                    }
                }
            },
            series: [{
                showInLegend: false,
                data: [ 121261, 48256, 13239, 12968, 9907, 5754, 5022, 4924, 3786, 2333 ]
            }]
        });
    });