Ask Your Question
4

How can I extend several lines horizontally along the x-axis in Highcharts?

asked 2022-08-02 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-04-23 20:00:00 +0000

ladyg gravatar image

You can extend several lines horizontally along the x-axis in Highcharts by using the following steps:

  1. First, define your chart options and add the necessary series data.

  2. Next, set the x and y values for each point in your series. For the y values, you can use an array to draw multiple lines.

  3. Then, set the lineWidth option for your series to the desired width.

  4. To extend the lines along the x-axis, you can set the pointStart and pointInterval options for the x-axis. The pointStart option sets the starting value for the first point in the series, and the pointInterval option sets the distance between each point along the x-axis.

  5. Finally, adjust any other chart options as needed, such as the chart title, legend, and axis labels.

Here's an example code snippet to illustrate how to extend multiple lines horizontally in Highcharts:

Highcharts.chart('container', {
    title: {
        text: 'Multiple Lines on X-Axis'
    },
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May']
        //Use pointStart and pointInterval options to extend lines horizontally
        pointStart: 0,
        pointInterval: 1,
    },
    yAxis: {
        title: {
            text: 'Values'
        }
    },
    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle'
    },
    series: [{
        name: 'Line 1',
        data: [5, 10, 15, 20, 25]
    }, {
        name: 'Line 2',
        //Draw multiple lines by using an array for y-values
        data: [[2, 8, 10, 16, 20]]
    }, {
        name: 'Line 3',
        data: [7, 14, 21, 28, 35]
    }],
    //Set the line width for each series
    plotOptions: {
        line: {
            lineWidth: 2
        }
    }
});

In this example, we have three series, each with different y-values but using the same x-axis categories. We set the pointStart option to 0 and the pointInterval option to 1 to extend the lines horizontally along the x-axis. We also set the lineWidth option to 2 for each series to make the lines thicker.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-08-02 11:00:00 +0000

Seen: 13 times

Last updated: Apr 23 '22