Home > Web Front-end > JS Tutorial > How to use trigonometric function plots to display data in Highcharts

How to use trigonometric function plots to display data in Highcharts

WBOY
Release: 2023-12-17 14:27:47
Original
1749 people have browsed it

How to use trigonometric function plots to display data in Highcharts

How to use trigonometric function charts to display data in Highcharts

Highcharts is a powerful JavaScript-based chart library that can help developers quickly create various type of dynamic chart. Among them, the trigonometric function chart is one of the common chart types, which can be drawn based on given data and functions.

This article will introduce how to use trigonometric function charts to display data in Highcharts, and provide specific code examples.

First, we need to introduce Highcharts and jQuery libraries into the HTML file:

<!DOCTYPE html>
<html>
<head>
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <script src="https://code.highcharts.com/highcharts.js"></script>
</head>
<body>
    <div id="container" style="width: 600px; height: 400px;"></div>
</body>
</html>
Copy after login

Next, we need to define some data for display. Suppose we want to display a chart of the sine function, we can use the following code to define the data:

var data = [];
for (var i = 0; i < 360; i++) {
    var x = i;
    var y = Math.sin((i * Math.PI) / 180); // 正弦函数
    data.push([x, y]);
}
Copy after login

Then, we can use the configuration options of Highcharts to create the chart. Here is the sample code to create a trigonometric function chart:

$(function() {
    Highcharts.chart('container', {
        title: {
            text: '三角函数图'
        },
        xAxis: {
            title: {
                text: '角度'
            }
        },
        yAxis: {
            title: {
                text: '值'
            }
        },
        series: [{
            name: '正弦函数',
            data: data,
            type: 'line'
        }]
    });
});
Copy after login

Finally, we put the above code into a <script> tag and place it in the &lt of the HTML file ;body>End of the tag:

<script>
    // 在这里插入代码
</script>
Copy after login

Now, when we refresh the browser, we can see the trigonometric function graph showing the sine function.

Through the above code examples, we can clearly see how to use trigonometric function charts to display data in Highcharts. Of course, this is just a simple example, you can customize the data and functions to create different trigonometric function charts according to your needs.

In actual applications, you can also change the style of the chart, add more data series, add legends, etc. Highcharts provides a wealth of configuration options and APIs to help you achieve more personalized needs.

I hope this article will help you understand how to use trigonometric function charts to display data in Highcharts!

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

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template