<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://cdn.jsdelivr.net/npm/highcharts@9.2.2/highcharts.js"></script> <script src="https://cdn.jsdelivr.net/npm/Faker.js"></script> <title>如何利用Highcharts中使用烛台图来展示数据</title> </head> <body> <div id="chart-container"></div> <script> let data = []; for (let i = 0; i < 100; i++) { let open = parseFloat(Faker.Finance.amount(1000, 5000)); let high = parseFloat(Faker.Finance.amount(open, open * 1.1)); let low = parseFloat(Faker.Finance.amount(open * 0.9, open)); let close = parseFloat(Faker.Finance.amount(low, high)); data.push([i, open, high, low, close]); } Highcharts.chart('chart-container', { chart: { type: 'candlestick' }, title: { text: '股票数据' }, xAxis: { labels: { formatter: function () { return data[this.value][0]; } } }, yAxis: { opposite: false, labels: { formatter: function () { return '$' + this.value; } } }, tooltip: { pointFormat: '<span style="font-weight:bold">{series.name}</span><br>' + '开盘价: <b>${point.open}</b><br/>' + '最高价: <b>${point.high}</b><br/>' + '最低价: <b>${point.low}</b><br/>' + '收盘价: <b>${point.close}</b><br/>' }, plotOptions: { candlestick: { color: '#0f0', upColor: '#f00', lineColor: '#000', upLineColor: '#000', lineWidth: 1 } }, series: [{ name: '股票价格', data: data }] }); </script> </body> </html>