index.htm 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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>Highcharts Example</title>
  7. <style type="text/css">
  8. .ld-label {
  9. width:200px;
  10. display: inline-block;
  11. }
  12. .ld-row {
  13. }
  14. .ld-url-input {
  15. width: 500px;
  16. }
  17. .ld-time-input {
  18. width: 40px;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <script src="../../code/highcharts.js"></script>
  24. <script src="../../code/modules/data.js"></script>
  25. <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
  26. <div class="ld-row">
  27. <label class="ld-label">
  28. Enable Polling
  29. </label>
  30. <input type="checkbox" checked="checked" id="enablePolling"/>
  31. </div>
  32. <div class="ld-row">
  33. <label class="ld-label">
  34. Polling Time (Seconds)
  35. </label>
  36. <input class="ld-time-input" type="number" value="2" id="pollingTime"/>
  37. </div>
  38. <div class="ld-row">
  39. <label class="ld-label">
  40. CSV URL
  41. </label>
  42. <input class="ld-url-input" type="text" id="fetchURL"/>
  43. </div>
  44. <script type="text/javascript">
  45. var defaultData = 'https://demo-live-data.highcharts.com/time-data.csv';
  46. var urlInput = document.getElementById('fetchURL');
  47. var pollingCheckbox = document.getElementById('enablePolling');
  48. var pollingInput = document.getElementById('pollingTime');
  49. function createChart() {
  50. Highcharts.chart('container', {
  51. chart: {
  52. type: 'spline'
  53. },
  54. title: {
  55. text: 'Live Data'
  56. },
  57. data: {
  58. csvURL: urlInput.value,
  59. enablePolling: pollingCheckbox.checked === true,
  60. dataRefreshRate: parseInt(pollingInput.value, 10)
  61. }
  62. });
  63. if (pollingInput.value < 1 || !pollingInput.value) {
  64. pollingInput.value = 1;
  65. }
  66. }
  67. urlInput.value = defaultData;
  68. // We recreate instead of using chart update to make sure the loaded CSV
  69. // and such is completely gone.
  70. pollingCheckbox.onchange = urlInput.onchange = pollingInput.onchange = createChart;
  71. // Create the chart
  72. createChart();
  73. </script>
  74. </body>
  75. </html>