Highcharts Scatter Plot

A scatter plot is a chart type that displays a set of data points as individual dots or markers, with the x-axis and y-axis representing the two variables being compared. Highcharts supports scatter plots with the chart.type option set to 'scatter'.

To create a scatter plot 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, create a Highcharts chart object and configure it with the data and chart options. For example:
Highcharts.chart('chart-container', {
  chart: {
    type: 'scatter'
  },
  title: {
    text: 'Scatter Plot'
  },
  xAxis: {
    title: {
      text: 'X Axis Label'
    }
  },
  yAxis: {
    title: {
      text: 'Y Axis Label'
    }
  },
  series: [{
    name: 'Series Name',
    data: [[1, 5], [2, 10], [3, 15], [4, 20], [5, 25]]
  }]
});

In this example, we're creating a scatter plot with the Highcharts chart function and passing in a set of options:

  • chart.type is set to 'scatter' to create a scatter plot
  • title.text is set to 'Scatter Plot' to set the main title
  • xAxis.title is used to set the label for the x-axis
  • yAxis.title is used to set the label for the y-axis
  • series is set to an array of objects with a name and data property to define the series data. The data property contains an array of arrays, where each inner array represents a data point with two values (the x and y coordinates).

With these options, you can create a scatter plot with customizable data and appearance. Note that Highcharts supports other options to customize the appearance of scatter plots, including the color, marker, and tooltip options.

  1. Customizing appearance in Highcharts Scatter Plot: To customize the appearance of a Scatter Plot in Highcharts, you can use various options like marker shapes, colors, and more. Here's an example code snippet:

    Highcharts.chart('container', {
        chart: {
            type: 'scatter'
        },
        plotOptions: {
            scatter: {
                marker: {
                    symbol: 'circle', // Change marker shape
                    radius: 8,
                    fillColor: 'rgba(150, 200, 100, 0.7)',
                    lineColor: 'white',
                    lineWidth: 2
                }
            }
        },
        series: [{
            name: 'Scatter Plot Data',
            data: [[10, 20], [30, 40], [50, 60]]
        }]
    });
    
  2. Adding data to Highcharts Scatter Plot: Adding data to a Scatter Plot involves specifying the x and y coordinates. Use the data property within the series object. Here's an example:

    series: [{
        name: 'Scatter Plot Data',
        data: [[10, 20], [30, 40], [50, 60]]
    }]
    
  3. Grouped Scatter Plot using Highcharts: To create a grouped Scatter Plot, you can use multiple series within the same chart. Here's an example:

    series: [{
        name: 'Group 1',
        data: [[10, 20], [30, 40], [50, 60]]
    }, {
        name: 'Group 2',
        data: [[15, 25], [35, 45], [55, 65]]
    }]
    
  4. Interactive features in Highcharts Scatter Plot: Highcharts supports interactive features like tooltips, click events, and legends in Scatter Plots. You can enable these features to enhance user interaction. Here's a snippet for tooltip configuration:

    tooltip: {
        pointFormat: 'X: {point.x}, Y: {point.y}'
    }
    
  5. Trendlines in Highcharts Scatter Plot: You can add trendlines to a Scatter Plot using the regression series type. Here's an example:

    series: [{
        type: 'scatter',
        name: 'Scatter Plot Data',
        data: [[10, 20], [30, 40], [50, 60]]
    }, {
        type: 'regression',
        name: 'Trendline',
        data: [[10, 20], [30, 40], [50, 60]]
    }]
    

    Note: Ensure you include the highcharts-regression module for regression analysis.