index.htm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>Highstock Example</title>
  7. <style type="text/css">
  8. </style>
  9. </head>
  10. <body>
  11. <script src="../../code/highstock.js"></script>
  12. <script src="../../code/modules/exporting.js"></script>
  13. <script src="../../code/modules/export-data.js"></script>
  14. <div id="container" style="height: 400px; min-width: 310px"></div>
  15. <script type="text/javascript">
  16. var seriesOptions = [],
  17. seriesCounter = 0,
  18. names = ['MSFT', 'AAPL', 'GOOG'];
  19. /**
  20. * Create the chart when all data is loaded
  21. * @returns {undefined}
  22. */
  23. function createChart() {
  24. Highcharts.stockChart('container', {
  25. rangeSelector: {
  26. selected: 4
  27. },
  28. yAxis: {
  29. labels: {
  30. formatter: function () {
  31. return (this.value > 0 ? ' + ' : '') + this.value + '%';
  32. }
  33. },
  34. plotLines: [{
  35. value: 0,
  36. width: 2,
  37. color: 'silver'
  38. }]
  39. },
  40. plotOptions: {
  41. series: {
  42. compare: 'percent',
  43. showInNavigator: true
  44. }
  45. },
  46. tooltip: {
  47. pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
  48. valueDecimals: 2,
  49. split: true
  50. },
  51. series: seriesOptions
  52. });
  53. }
  54. function success(data) {
  55. var name = this.url.match(/(msft|aapl|goog)/)[0].toUpperCase();
  56. var i = names.indexOf(name);
  57. seriesOptions[i] = {
  58. name: name,
  59. data: data
  60. };
  61. // As we're loading the data asynchronously, we don't know what order it
  62. // will arrive. So we keep a counter and create the chart when all the data is loaded.
  63. seriesCounter += 1;
  64. if (seriesCounter === names.length) {
  65. createChart();
  66. }
  67. }
  68. Highcharts.getJSON(
  69. 'https://cdn.jsdelivr.net/gh/highcharts/highcharts@v7.0.0/samples/data/msft-c.json',
  70. success
  71. );
  72. Highcharts.getJSON(
  73. 'https://cdn.jsdelivr.net/gh/highcharts/highcharts@v7.0.0/samples/data/aapl-c.json',
  74. success
  75. );
  76. Highcharts.getJSON(
  77. 'https://cdn.jsdelivr.net/gh/highcharts/highcharts@v7.0.0/samples/data/goog-c.json',
  78. success
  79. );
  80. </script>
  81. </body>
  82. </html>