Highcharts Basic Column Chart

To create a basic column chart using Highcharts, you can follow these steps:

  • Include the Highcharts library in your HTML file. You can either download it from the Highcharts website or include it from a CDN like this:
<script src="https://code.highcharts.com/highcharts.js"></script>
  • Create a container element for the chart in your HTML file, like this:
<div id="chart-container"></div>
  • In your JavaScript code, define the data for the chart in an array of numbers or objects. For example, here's an array of numbers:
var data = [5, 3, 4, 7, 2];

Or, here's an array of objects with 'name' and 'y' properties:

var data = [
  { name: 'Apples', y: 5 },
  { name: 'Oranges', y: 3 },
  { name: 'Bananas', y: 4 },
  { name: 'Pears', y: 7 },
  { name: 'Grapes', y: 2 }
];
  • Create a Highcharts chart object and configure it with the data and chart options. In this case, we want a column chart, so we'll set the chart type to 'column', and we'll use the 'data' option to specify the data for the chart, like this:
Highcharts.chart('chart-container', {
  chart: {
    type: 'column'
  },
  title: {
    text: 'Basic Column Chart'
  },
  xAxis: {
    type: 'category'
  },
  yAxis: {
    title: {
      text: 'Value'
    }
  },
  series: [{
    name: 'Data',
    data: data
  }]
});

Note that we're using the 'data' option to specify the data for the chart, and the 'xAxis' option to set the type of the x-axis to 'category'.

  • Finally, add some CSS to style the chart container and make it responsive, like this:
#chart-container {
  width: 100%;
  height: 500px;
  max-width: 800px;
  margin: 0 auto;
}

This will create a basic column chart using the specified data and options, and render it in the 'chart-container' element on your web page. You can customize the chart further by adjusting the options and adding additional features, like tooltips, legends, and labels.

  1. Customizing appearance in Highcharts Basic Column Chart:

    • Customize the appearance by modifying various chart options such as colors, border styles, and column width.
    Highcharts.chart('container', {
        chart: {
            type: 'column',
            backgroundColor: '#f2f2f2'
        },
        plotOptions: {
            column: {
                color: '#64b4dc', // Column color
                borderWidth: 1, // Border width
                borderColor: '#3582c4', // Border color
                pointWidth: 20 // Column width
            }
        },
        series: [{
            data: [10, 15, 7, 22, 11]
        }],
        // Other configuration options...
    });
    
  2. Adding data to Highcharts Basic Column Chart:

    • Add data for each column within the series array to create a Basic Column Chart.
    Highcharts.chart('container', {
        chart: {
            type: 'column'
        },
        series: [{
            data: [10, 15, 7, 22, 11]
        }],
        // Other configuration options...
    });
    
  3. Stacked Basic Column Chart in Highcharts:

    • Create a stacked Basic Column Chart by configuring the stacking option.
    Highcharts.chart('container', {
        chart: {
            type: 'column'
        },
        plotOptions: {
            column: {
                stacking: 'normal' // Stack columns on top of each other
            }
        },
        series: [{
            name: 'Series 1',
            data: [10, 15, 7, 22, 11]
        }, {
            name: 'Series 2',
            data: [5, 10, 5, 15, 7]
        }],
        // Other configuration options...
    });
    
  4. Grouped Basic Column Chart using Highcharts:

    • Create a grouped Basic Column Chart by configuring the grouping option.
    Highcharts.chart('container', {
        chart: {
            type: 'column'
        },
        plotOptions: {
            column: {
                grouping: false // Display columns side by side
            }
        },
        series: [{
            name: 'Series 1',
            data: [10, 15, 7, 22, 11]
        }, {
            name: 'Series 2',
            data: [5, 10, 5, 15, 7]
        }],
        // Other configuration options...
    });
    
  5. Interactive features in Highcharts Basic Column Chart:

    • Enable interactive features like tooltips, data labels, and events for a richer user experience.
    Highcharts.chart('container', {
        chart: {
            type: 'column'
        },
        plotOptions: {
            column: {
                dataLabels: {
                    enabled: true, // Show data labels
                    format: '{y}' // Data label format
                }
            }
        },
        series: [{
            data: [10, 15, 7, 22, 11]
        }],
        // Other configuration options...
    });