• Edit
  • Download
    1. <!DOCTYPE html>
    2. <html>
    3.  
    4. <head>
    5. <meta charset="utf-8">
    6. <title>ZingGrid: Blank Grid</title>
    7. <script nonce="undefined" src="https://cdn.zingchart.com/zingchart.min.js"></script>
    8. <style>
    9. html,
    10. body {
    11. height: 100%;
    12. width: 100%;
    13. margin: 0;
    14. padding: 0;
    15. }
    16.  
    17. #myChart {
    18. margin: 0 auto;
    19. height: 380px;
    20. width: 98%;
    21. box-shadow: 5px 5px 5px #eee;
    22. background-color: #fff;
    23. border: 1px solid #eee;
    24. display: flex;
    25. flex-flow: column wrap;
    26. }
    27.  
    28. .controls--container {
    29. display: flex;
    30. align-items: center;
    31. justify-content: center;
    32. }
    33.  
    34. .controls--container button {
    35. margin: 40px;
    36. padding: 15px;
    37. background-color: #FF4081;
    38. border: none;
    39. color: #fff;
    40. box-shadow: 5px 5px 5px #eee;
    41. font-size: 16px;
    42. font-family: Roboto;
    43. cursor: pointer;
    44. transition: .1s;
    45. }
    46.  
    47. .controls--container button:hover {
    48. opacity: .9;
    49. }
    50.  
    51. /*button movement*/
    52. .controls--container button:active {
    53. border-width: 0 0 2px 0;
    54. transform: translateY(8px);
    55. opacity: 0.9;
    56. }
    57.  
    58. .zc-ref {
    59. display: none;
    60. }
    61. </style>
    62. </head>
    63.  
    64. <body>
    65. <!-- CHART CONTAINER -->
    66. <div id="myChart">
    67. <a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a>
    68. </div>
    69. <div class="controls--container">
    70. <button id="get">get</button>
    71. <button id="set">Set</button>
    72. <span id="output">Interval is: 500</span>
    73. </div>
    74. <script>
    75. ZC.LICENSE = ["569d52cefae586f634c54f86dc99e6a9", "b55b025e438fa8a98e32482b5f768ff5"]; //real-time feed random math function
    76. function realTimeFeed(callback) {
    77. var tick = {};
    78. tick.plot0 = parseInt(10 + 90 * Math.random(), 10);
    79. tick.plot1 = parseInt(10 + 90 * Math.random(), 10);
    80. callback(JSON.stringify(tick));
    81. };
    82.  
    83. // define top level feed control functions
    84. function getInterval() {
    85. let interval = zingchart.exec('myChart', 'getinterval');
    86. output.textContent = `Interval is: ${interval}`;
    87. }
    88.  
    89. function setInterval() {
    90. let interval = Math.floor(Math.random() * (1000 - 50)) + 50;
    91. zingchart.exec('myChart', 'setinterval', {
    92. interval: interval,
    93. update: false
    94. });
    95. output.textContent = `Interval is: ${interval}`;
    96. }
    97.  
    98.  
    99. // window:load event for Javascript to run after HTML
    100. // because this Javascript is injected into the document head
    101. window.addEventListener('load', () => {
    102. // Javascript code to execute after DOM content
    103.  
    104. //clear start stop click events
    105. document.getElementById('get').addEventListener('click', getInterval);
    106. document.getElementById('set').addEventListener('click', setInterval);
    107.  
    108. // full ZingChart schema can be found here:
    109. // https://www.zingchart.com/docs/api/json-configuration/
    110. const myConfig = {
    111. //chart styling
    112. type: 'line',
    113. globals: {
    114. fontFamily: 'Roboto',
    115. },
    116. backgroundColor: '#fff',
    117. title: {
    118. backgroundColor: '#1565C0',
    119. text: 'Real-Time Line Chart',
    120. color: '#fff',
    121. height: '30x',
    122. },
    123. plotarea: {
    124. marginTop: '80px'
    125. },
    126. crosshairX: {
    127. lineWidth: 4,
    128. lineStyle: 'dashed',
    129. lineColor: '#424242',
    130. marker: {
    131. visible: true,
    132. size: 9
    133. },
    134. plotLabel: {
    135. backgroundColor: '#fff',
    136. borderColor: '#e3e3e3',
    137. borderRadius: 5,
    138. padding: 15,
    139. fontSize: 15,
    140. shadow: true,
    141. shadowAlpha: 0.2,
    142. shadowBlur: 5,
    143. shadowDistance: 4,
    144. },
    145. scaleLabel: {
    146. backgroundColor: '#424242',
    147. padding: 5
    148. }
    149. },
    150. scaleY: {
    151. guide: {
    152. visible: false
    153. },
    154. values: '0:100:25'
    155. },
    156. tooltip: {
    157. visible: false
    158. },
    159. //real-time feed
    160. refresh: {
    161. type: 'feed',
    162. transport: 'js',
    163. url: 'realTimeFeed()',
    164. interval: 500,
    165. },
    166. plot: {
    167. shadow: 1,
    168. shadowColor: '#eee',
    169. shadowDistance: '10px',
    170. lineWidth: 5,
    171. hoverState: {
    172. visible: false
    173. },
    174. marker: {
    175. visible: false
    176. },
    177. aspect: 'spline'
    178. },
    179. series: [{
    180. values: [],
    181. lineColor: '#2196F3',
    182. text: 'Blue Line'
    183. }, {
    184. values: [],
    185. lineColor: '#ff9800',
    186. text: 'Orange Line'
    187. }]
    188. };
    189.  
    190. // render chart with width and height to
    191. // fill the parent container CSS dimensions
    192. zingchart.render({
    193. id: 'myChart',
    194. data: myConfig,
    195. height: '100%',
    196. width: '100%',
    197. });
    198. });
    199. </script>
    200. </body>
    201.  
    202. </html>
    1. <!DOCTYPE html>
    2. <html>
    3.  
    4. <head>
    5. <meta charset="utf-8">
    6. <title>ZingGrid: Blank Grid</title>
    7. <script src="https://cdn.zingchart.com/zingchart.min.js"></script>
    8. </head>
    9.  
    10. <body>
    11. <!-- CHART CONTAINER -->
    12. <div id="myChart">
    13. <a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a>
    14. </div>
    15. <div class="controls--container">
    16. <button id="get">get</button>
    17. <button id="set">Set</button>
    18. <span id="output">Interval is: 500</span>
    19. </div>
    20. </body>
    21.  
    22. </html>
    1. html,
    2. body {
    3. height: 100%;
    4. width: 100%;
    5. margin: 0;
    6. padding: 0;
    7. }
    8.  
    9. #myChart {
    10. margin: 0 auto;
    11. height: 380px;
    12. width: 98%;
    13. box-shadow: 5px 5px 5px #eee;
    14. background-color: #fff;
    15. border: 1px solid #eee;
    16. display: flex;
    17. flex-flow: column wrap;
    18. }
    19.  
    20. .controls--container {
    21. display: flex;
    22. align-items: center;
    23. justify-content: center;
    24. }
    25.  
    26. .controls--container button {
    27. margin: 40px;
    28. padding: 15px;
    29. background-color: #FF4081;
    30. border: none;
    31. color: #fff;
    32. box-shadow: 5px 5px 5px #eee;
    33. font-size: 16px;
    34. font-family: Roboto;
    35. cursor: pointer;
    36. transition: .1s;
    37. }
    38.  
    39. .controls--container button:hover {
    40. opacity: .9;
    41. }
    42.  
    43. /*button movement*/
    44. .controls--container button:active {
    45. border-width: 0 0 2px 0;
    46. transform: translateY(8px);
    47. opacity: 0.9;
    48. }
    49.  
    50. .zc-ref {
    51. display: none;
    52. }
    1. //real-time feed random math function
    2. function realTimeFeed(callback) {
    3. var tick = {};
    4. tick.plot0 = parseInt(10 + 90 * Math.random(), 10);
    5. tick.plot1 = parseInt(10 + 90 * Math.random(), 10);
    6. callback(JSON.stringify(tick));
    7. };
    8.  
    9. // define top level feed control functions
    10. function getInterval() {
    11. let interval = zingchart.exec('myChart', 'getinterval');
    12. output.textContent = `Interval is: ${interval}`;
    13. }
    14.  
    15. function setInterval() {
    16. let interval = Math.floor(Math.random() * (1000 - 50)) + 50;
    17. zingchart.exec('myChart', 'setinterval', {
    18. interval: interval,
    19. update: false
    20. });
    21. output.textContent = `Interval is: ${interval}`;
    22. }
    23.  
    24.  
    25. // window:load event for Javascript to run after HTML
    26. // because this Javascript is injected into the document head
    27. window.addEventListener('load', () => {
    28. // Javascript code to execute after DOM content
    29.  
    30. //clear start stop click events
    31. document.getElementById('get').addEventListener('click', getInterval);
    32. document.getElementById('set').addEventListener('click', setInterval);
    33.  
    34. // full ZingChart schema can be found here:
    35. // https://www.zingchart.com/docs/api/json-configuration/
    36. const myConfig = {
    37. //chart styling
    38. type: 'line',
    39. globals: {
    40. fontFamily: 'Roboto',
    41. },
    42. backgroundColor: '#fff',
    43. title: {
    44. backgroundColor: '#1565C0',
    45. text: 'Real-Time Line Chart',
    46. color: '#fff',
    47. height: '30x',
    48. },
    49. plotarea: {
    50. marginTop: '80px'
    51. },
    52. crosshairX: {
    53. lineWidth: 4,
    54. lineStyle: 'dashed',
    55. lineColor: '#424242',
    56. marker: {
    57. visible: true,
    58. size: 9
    59. },
    60. plotLabel: {
    61. backgroundColor: '#fff',
    62. borderColor: '#e3e3e3',
    63. borderRadius: 5,
    64. padding: 15,
    65. fontSize: 15,
    66. shadow: true,
    67. shadowAlpha: 0.2,
    68. shadowBlur: 5,
    69. shadowDistance: 4,
    70. },
    71. scaleLabel: {
    72. backgroundColor: '#424242',
    73. padding: 5
    74. }
    75. },
    76. scaleY: {
    77. guide: {
    78. visible: false
    79. },
    80. values: '0:100:25'
    81. },
    82. tooltip: {
    83. visible: false
    84. },
    85. //real-time feed
    86. refresh: {
    87. type: 'feed',
    88. transport: 'js',
    89. url: 'realTimeFeed()',
    90. interval: 500,
    91. },
    92. plot: {
    93. shadow: 1,
    94. shadowColor: '#eee',
    95. shadowDistance: '10px',
    96. lineWidth: 5,
    97. hoverState: {
    98. visible: false
    99. },
    100. marker: {
    101. visible: false
    102. },
    103. aspect: 'spline'
    104. },
    105. series: [{
    106. values: [],
    107. lineColor: '#2196F3',
    108. text: 'Blue Line'
    109. }, {
    110. values: [],
    111. lineColor: '#ff9800',
    112. text: 'Orange Line'
    113. }]
    114. };
    115.  
    116. // render chart with width and height to
    117. // fill the parent container CSS dimensions
    118. zingchart.render({
    119. id: 'myChart',
    120. data: myConfig,
    121. height: '100%',
    122. width: '100%',
    123. });
    124. });