• Edit
  • Download
    1. <!DOCTYPE html>
    2. <html>
    3.  
    4. <head>
    5. <meta charset="utf-8">
    6. <title>ZingSoft Demo</title>
    7.  
    8. <script nonce="undefined" src="https://cdn.zingchart.com/zingchart.min.js"></script>
    9. <style>
    10. html,
    11. body,
    12. #myChart {
    13. height: 100%;
    14. width: 100%;
    15. }
    16. </style>
    17. </head>
    18.  
    19. <body>
    20. <div id='myChart'></div>
    21. <script>
    22. ZC.LICENSE = ["569d52cefae586f634c54f86dc99e6a9", "b55b025e438fa8a98e32482b5f768ff5"];
    23. var myConfig = {
    24. type: "line",
    25. title: {
    26. text: "Click a data point to add a marker"
    27. },
    28. plot: {
    29. tooltip: {
    30. visible: false
    31. },
    32. cursor: 'hand'
    33. },
    34. scaleX: {
    35. markers: [],
    36. labels: ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun']
    37. },
    38. series: [{
    39. values: [35, 42, 67, 89, 25, 34, 67]
    40. },
    41. {
    42. values: [35, 42, 67, 89, 25, 34, 67].sort()
    43. }
    44. ]
    45. };
    46.  
    47. zingchart.render({
    48. id: 'myChart',
    49. data: myConfig,
    50. height: '100%',
    51. width: '100%'
    52. });
    53.  
    54. /*
    55. * define marker class to construct
    56. * markers on the fly easier.
    57. */
    58. function Marker(_index, _plotindex) {
    59. return {
    60. type: 'line',
    61. lineColor: (_plotindex == 0) ? '#4CAF50' : '#FFC107',
    62. lineWidth: 5,
    63. offsetX: (_plotindex == 0) ? -2 : 2, //offset markers to prevent overlap
    64. range: [_index],
    65. }
    66. }
    67.  
    68. // global array for markers since you can only update the whole array
    69. var markersArray = [];
    70.  
    71. // hash table for markers
    72. var markerHashTable = {};
    73. markerHashTable['plotindex_0'] = {};
    74. markerHashTable['plotindex_1'] = {};
    75.  
    76. /*
    77. * Register a node_click event and then render a chart with the markers
    78. */
    79. zingchart.bind('myChart', 'node_click', function(e) {
    80. //console.log(e)
    81.  
    82. // check hash table. Add marker
    83. if (!markerHashTable['plotindex_' + e.plotindex][e.nodeindex]) {
    84.  
    85. // create a marker
    86. var newMarker = new Marker(e.nodeindex, e.plotindex);
    87.  
    88. markerHashTable['plotindex_' + e.plotindex][e.nodeindex] = true;
    89. markersArray.push(newMarker);
    90.  
    91. // render the marker
    92. myConfig.scaleX.markers = markersArray;
    93. zingchart.exec('myChart', 'setdata', {
    94. data: myConfig
    95. });
    96. }
    97.  
    98. });
    99. </script>
    100. </body>
    101.  
    102. </html>
    1. <!DOCTYPE html>
    2. <html>
    3.  
    4. <head>
    5. <meta charset="utf-8">
    6. <title>ZingSoft Demo</title>
    7.  
    8. <script src="https://cdn.zingchart.com/zingchart.min.js"></script>
    9. </head>
    10.  
    11. <body>
    12. <div id='myChart'></div>
    13. </body>
    14.  
    15. </html>
    1. html,
    2. body,
    3. #myChart {
    4. height: 100%;
    5. width: 100%;
    6. }
    1. var myConfig = {
    2. type: "line",
    3. title: {
    4. text: "Click a data point to add a marker"
    5. },
    6. plot: {
    7. tooltip: {
    8. visible: false
    9. },
    10. cursor: 'hand'
    11. },
    12. scaleX: {
    13. markers: [],
    14. labels: ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun']
    15. },
    16. series: [{
    17. values: [35, 42, 67, 89, 25, 34, 67]
    18. },
    19. {
    20. values: [35, 42, 67, 89, 25, 34, 67].sort()
    21. }
    22. ]
    23. };
    24.  
    25. zingchart.render({
    26. id: 'myChart',
    27. data: myConfig,
    28. height: '100%',
    29. width: '100%'
    30. });
    31.  
    32. /*
    33. * define marker class to construct
    34. * markers on the fly easier.
    35. */
    36. function Marker(_index, _plotindex) {
    37. return {
    38. type: 'line',
    39. lineColor: (_plotindex == 0) ? '#4CAF50' : '#FFC107',
    40. lineWidth: 5,
    41. offsetX: (_plotindex == 0) ? -2 : 2, //offset markers to prevent overlap
    42. range: [_index],
    43. }
    44. }
    45.  
    46. // global array for markers since you can only update the whole array
    47. var markersArray = [];
    48.  
    49. // hash table for markers
    50. var markerHashTable = {};
    51. markerHashTable['plotindex_0'] = {};
    52. markerHashTable['plotindex_1'] = {};
    53.  
    54. /*
    55. * Register a node_click event and then render a chart with the markers
    56. */
    57. zingchart.bind('myChart', 'node_click', function(e) {
    58. //console.log(e)
    59.  
    60. // check hash table. Add marker
    61. if (!markerHashTable['plotindex_' + e.plotindex][e.nodeindex]) {
    62.  
    63. // create a marker
    64. var newMarker = new Marker(e.nodeindex, e.plotindex);
    65.  
    66. markerHashTable['plotindex_' + e.plotindex][e.nodeindex] = true;
    67. markersArray.push(newMarker);
    68.  
    69. // render the marker
    70. myConfig.scaleX.markers = markersArray;
    71. zingchart.exec('myChart', 'setdata', {
    72. data: myConfig
    73. });
    74. }
    75.  
    76. });