Table of Contents
Step 1: Prepare data
Step 2: Create a container
Step 3: Introduce the Highcharts library
Step 4: Write the Highcharts configuration
Step 5: Display the chart
Home Web Front-end JS Tutorial How to use horizontal line charts to display data in Highcharts

How to use horizontal line charts to display data in Highcharts

Dec 18, 2023 pm 02:21 PM
highcharts Data Display horizontal line chart

How to use horizontal line charts to display data in Highcharts

Highcharts is a very popular JavaScript chart library that supports multiple chart types to display data. Among them, the horizontal line chart is a commonly used chart type used to display the horizontal position of a certain value in the data.

This article will introduce how to use horizontal line charts in Highcharts to display data and provide specific code examples. The following are the steps:

Step 1: Prepare data

First you need to prepare the data, such as the following data:

var data = [{
    name: 'Apple',
    value: 85
}, {
    name: 'Orange',
    value: 65
}, {
    name: 'Banana',
    value: 45
}, {
    name: 'Grape',
    value: 30
}, {
    name: 'Lemon',
    value: 15
}];
Copy after login

In the above data, name represents the name of the horizontal line, and value represents the horizontal line value. Here we use 5 types of horizontal lines, which can be increased or decreased as needed.

Step 2: Create a container

Create an HTML container for placing Highcharts charts. For example:

<div id="container"></div>
Copy after login

Step 3: Introduce the Highcharts library

Introduce the Highcharts library into the HTML page. For example:

<script src="https://cdn.jsdelivr.net/npm/highcharts@9.1.1/highcharts.js"></script>
Copy after login

Step 4: Write the Highcharts configuration

Write the Highcharts configuration in the JavaScript file, including the title, data, x-axis, y-axis, etc. of the horizontal line chart. The type of horizontal line chart is xrange. The specific configuration code is as follows:

Highcharts.chart('container', {
    chart: {
        type: 'xrange'
    },
    title: {
        text: 'Horizontal Line Chart'
    },
    xAxis: {
        categories: ['Value'],
    },
    yAxis: {
        title: {
            text: ''
        },
        reversed: true,
        maxPadding: 0.1,
        min: 0,
        max: 100,
    },
    legend: {
        enabled: false
    },
    series: [{
        name: 'Value',
        data: data,
        borderRadius: 5,
        borderColor: '#cccccc',
        borderWidth: 1,
        pointWidth: 20
    }]
});
Copy after login

In the above configuration, the chart type is xrange, which means generating a horizontal line chart. title represents the chart title, xAxis represents the x-axis, and there is only one "Value" item in categories because there is only one x-axis in the horizontal line chart. yAxis represents the y-axis, reversed represents flipping the y-axis so that the highest value is at the top; maxPadding represents the proportion of space left above and below the y-axis, and min and max represent the minimum and maximum values ​​of the y-axis. legend represents the legend, which is not needed here, so it is set to false. series represents the data series, where name is the name of the data series, data is the data, borderRadius represents the border fillet radius, borderColor represents the border color, borderWidth represents the border width, and pointWidth represents the width of the horizontal line.

Step 5: Display the chart

Finally, call the Highcharts configuration in the HTML page and display the chart in the container.

Highcharts.chart('container', options);
Copy after login

The complete code is as follows:




    Horizontal Line Chart
    <script src="https://cdn.jsdelivr.net/npm/highcharts@9.1.1/highcharts.js"></script>


    <div id="container"></div>

    <script>
        var data = [{
            name: 'Apple',
            value: 85
        }, {
            name: 'Orange',
            value: 65
        }, {
            name: 'Banana',
            value: 45
        }, {
            name: 'Grape',
            value: 30
        }, {
            name: 'Lemon',
            value: 15
        }];

        var options = {
            chart: {
                type: 'xrange'
            },
            title: {
                text: 'Horizontal Line Chart'
            },
            xAxis: {
                categories: ['Value']
            },
            yAxis: {
                title: {
                    text: ''
                },
                reversed: true,
                maxPadding: 0.1,
                min: 0,
                max: 100
            },
            legend: {
                enabled: false
            },
            series: [{
                name: 'Value',
                data: data,
                borderRadius: 5,
                borderColor: '#cccccc',
                borderWidth: 1,
                pointWidth: 20
            }]
        };

        Highcharts.chart('container', options);
    </script>

Copy after login

The above are all the steps to use the horizontal line chart in Highcharts to display data. I hope to be helpful.

The above is the detailed content of How to use horizontal line charts to display data in Highcharts. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Sankey chart to display data in Highcharts How to use Sankey chart to display data in Highcharts Dec 17, 2023 pm 04:41 PM

How to use Sankey diagram to display data in Highcharts Sankey diagram (SankeyDiagram) is a chart type used to visualize complex processes such as flow, energy, and funds. It can clearly display the relationship and flow between various nodes, and can help us better understand and analyze data. In this article, we will introduce how to use Highcharts to create and customize a Sankey chart, with specific code examples. First, we need to load the Highcharts library and Sank

How to use dynamic data in Highcharts to display real-time data How to use dynamic data in Highcharts to display real-time data Dec 17, 2023 pm 06:57 PM

How to use dynamic data in Highcharts to display real-time data. With the advent of the big data era, the display of real-time data has become more and more important. Highcharts, as a popular charting library, provides rich functions and customizability, allowing us to flexibly display real-time data. This article will introduce how to use dynamic data in Highcharts to display real-time data, and give specific code examples. First, we need to prepare a data source that can provide real-time data. In this article, I

How to create a Gantt chart using Highcharts How to create a Gantt chart using Highcharts Dec 17, 2023 pm 07:23 PM

How to use Highcharts to create a Gantt chart requires specific code examples. Introduction: The Gantt chart is a chart form commonly used to display project progress and time management. It can visually display the start time, end time and progress of the task. Highcharts is a powerful JavaScript chart library that provides rich chart types and flexible configuration options. This article will introduce how to use Highcharts to create a Gantt chart and give specific code examples. 1. Highchart

How to use stacked charts to display data in Highcharts How to use stacked charts to display data in Highcharts Dec 18, 2023 pm 05:56 PM

How to use stacked charts to display data in Highcharts Stacked charts are a common way of visualizing data, which can display the sum of multiple data series at the same time and display the contribution of each data series in the form of a bar chart. Highcharts is a powerful JavaScript library that provides a rich variety of charts and flexible configuration options to meet various data visualization needs. In this article, we will introduce how to use Highcharts to create a stacked chart and provide

How to use histogram to display data in ECharts How to use histogram to display data in ECharts Dec 18, 2023 pm 02:21 PM

How to use histograms to display data in ECharts ECharts is a JavaScript-based data visualization library that is very popular and widely used in the field of data visualization. Among them, the histogram is the most common and commonly used chart type, which can be used to display the size, comparison and trend analysis of various numerical data. This article will introduce how to use ECharts to draw histograms and provide code examples. First, we need to introduce the ECharts library into the HTML file, which can be introduced in the following way

How to use Vue to implement statistical charts for large-screen data display How to use Vue to implement statistical charts for large-screen data display Aug 17, 2023 am 09:54 AM

How to use Vue to implement statistical charts for large-screen data display. In the modern information society, data statistics and visualization have become important means of decision-making and analysis. In order to display data more intuitively, we often use statistical charts. Under the Vue framework, you can easily achieve large-screen data display needs by using some excellent chart libraries. This article will introduce how to use Vue combined with two mainstream statistical chart libraries, echarts and chart.js, to display data. First, we need to install echarts and c for the Vue project

How to create a map heat map using Highcharts How to create a map heat map using Highcharts Dec 17, 2023 pm 04:06 PM

How to use Highcharts to create a map heat map requires specific code examples. A heat map is a visual data display method that can represent the data distribution in each area through different color shades. In the field of data visualization, Highcharts is a very popular JavaScript library that provides rich chart types and interactive functions. This article will introduce how to use Highcharts to create a map heat map and provide specific code examples. First, we need to prepare some data

How to use scatter plots to display data in Highcharts How to use scatter plots to display data in Highcharts Dec 17, 2023 pm 10:30 PM

How to use scatter plots to display data in Highcharts Preface Highcharts is an open source JavaScript chart library that provides a variety of chart types and powerful customization functions. Among them, scatter plot is a commonly used data visualization method that can show the relationship between two variables and the distribution of variables. This article will introduce how to use scatter plots to display data in Highcharts and provide specific code examples. Step 1: Introduce the Highcharts library

See all articles