Highcharts Basic Area Chart

To create a basic area 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 'x' and 'y' properties:

var data = [
  { x: 1, y: 5 },
  { x: 2, y: 3 },
  { x: 3, y: 4 },
  { x: 4, y: 7 },
  { x: 5, y: 2 }
];
  • Create a Highcharts chart object and configure it with the data and chart options. In this case, we want an area chart, so we'll set the chart type to 'area', and we'll use the 'data' option to specify the data for the chart, like this:
Highcharts.chart('chart-container', {
  chart: {
    type: 'area'
  },
  title: {
    text: 'Basic Area 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 area 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 Area Chart:

    • Customize the appearance by modifying various chart options such as colors, opacity, and border styles.
    Highcharts.chart('container', {
        chart: {
            type: 'area',
            backgroundColor: '#f2f2f2'
        },
        plotOptions: {
            area: {
                fillColor: 'rgba(100, 180, 220, 0.5)', // Area color with opacity
                lineColor: '#64b4dc', // Line color
                lineWidth: 2 // Line width
            }
        },
        series: [{
            data: [10, 15, 7, 22, 11]
        }],
        // Other configuration options...
    });
    
  2. Adding data to Highcharts Basic Area Chart:

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

    • Create a stacked Basic Area Chart by configuring the stacking option.
    Highcharts.chart('container', {
        chart: {
            type: 'area'
        },
        plotOptions: {
            area: {
                stacking: 'normal' // Stack areas 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 Area Chart using Highcharts:

    • Create a grouped Basic Area Chart by configuring the grouping option.
    Highcharts.chart('container', {
        chart: {
            type: 'area'
        },
        plotOptions: {
            area: {
                grouping: false // Display areas 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 Area Chart:

    • Enable interactive features like tooltips, data labels, and events for a richer user experience.
    Highcharts.chart('container', {
        chart: {
            type: 'area'
        },
        plotOptions: {
            area: {
                marker: {
                    enabled: true, // Show markers at data points
                    radius: 4 // Marker size
                }
            }
        },
        series: [{
            data: [10, 15, 7, 22, 11]
        }],
        // Other configuration options...
    });