• Edit
  • Download
  • <!DOCTYPE html>
    <html>
    
    <head>
      <meta charset="utf-8">
      <title>ZingSoft Demo</title>
    
      <script nonce="undefined" src="https://cdn.zingchart.com/zingchart.min.js"></script>
      <style>
        html,
        body,
        #myChart {
          height: 100%;
          width: 100%;
        }
      </style>
    </head>
    
    <body>
      <div id='myChart'></div>
      <script>
        ZC.LICENSE = ["569d52cefae586f634c54f86dc99e6a9", "b55b025e438fa8a98e32482b5f768ff5"];
        var myConfig = {
          type: "line",
          title: {
            text: "Click a data point to add a marker"
          },
          plot: {
            tooltip: {
              visible: false
            },
            cursor: 'hand'
          },
          scaleX: {
            markers: [],
            labels: ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun']
          },
          series: [{
              values: [35, 42, 67, 89, 25, 34, 67]
            },
            {
              values: [35, 42, 67, 89, 25, 34, 67].sort()
            }
          ]
        };
    
        zingchart.render({
          id: 'myChart',
          data: myConfig,
          height: '100%',
          width: '100%'
        });
    
        /*
         * define marker class to construct
         * markers on the fly easier.
         */
        function Marker(_index, _plotindex) {
          return {
            type: 'line',
            lineColor: (_plotindex == 0) ? '#4CAF50' : '#FFC107',
            lineWidth: 5,
            offsetX: (_plotindex == 0) ? -2 : 2, //offset markers to prevent overlap
            range: [_index],
          }
        }
    
        // global array for markers since you can only update the whole array
        var markersArray = [];
    
        // hash table for markers
        var markerHashTable = {};
        markerHashTable['plotindex_0'] = {};
        markerHashTable['plotindex_1'] = {};
    
        /*
         * Register a node_click event and then render a chart with the markers
         */
        zingchart.bind('myChart', 'node_click', function(e) {
          //console.log(e)
    
          // check hash table. Add marker
          if (!markerHashTable['plotindex_' + e.plotindex][e.nodeindex]) {
    
            // create a marker
            var newMarker = new Marker(e.nodeindex, e.plotindex);
    
            markerHashTable['plotindex_' + e.plotindex][e.nodeindex] = true;
            markersArray.push(newMarker);
    
            // render the marker
            myConfig.scaleX.markers = markersArray;
            zingchart.exec('myChart', 'setdata', {
              data: myConfig
            });
          }
    
        });
      </script>
    </body>
    
    </html>
    <!DOCTYPE html>
    <html>
    
    <head>
      <meta charset="utf-8">
      <title>ZingSoft Demo</title>
    
      <script src="https://cdn.zingchart.com/zingchart.min.js"></script>
    </head>
    
    <body>
      <div id='myChart'></div>
    </body>
    
    </html>
    html,
    body,
    #myChart {
      height: 100%;
      width: 100%;
    }
    var myConfig = {
      type: "line",
      title: {
        text: "Click a data point to add a marker"
      },
      plot: {
        tooltip: {
          visible: false
        },
        cursor: 'hand'
      },
      scaleX: {
        markers: [],
        labels: ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun']
      },
      series: [{
          values: [35, 42, 67, 89, 25, 34, 67]
        },
        {
          values: [35, 42, 67, 89, 25, 34, 67].sort()
        }
      ]
    };
    
    zingchart.render({
      id: 'myChart',
      data: myConfig,
      height: '100%',
      width: '100%'
    });
    
    /*
     * define marker class to construct
     * markers on the fly easier.
     */
    function Marker(_index, _plotindex) {
      return {
        type: 'line',
        lineColor: (_plotindex == 0) ? '#4CAF50' : '#FFC107',
        lineWidth: 5,
        offsetX: (_plotindex == 0) ? -2 : 2, //offset markers to prevent overlap
        range: [_index],
      }
    }
    
    // global array for markers since you can only update the whole array
    var markersArray = [];
    
    // hash table for markers
    var markerHashTable = {};
    markerHashTable['plotindex_0'] = {};
    markerHashTable['plotindex_1'] = {};
    
    /*
     * Register a node_click event and then render a chart with the markers
     */
    zingchart.bind('myChart', 'node_click', function(e) {
      //console.log(e)
    
      // check hash table. Add marker
      if (!markerHashTable['plotindex_' + e.plotindex][e.nodeindex]) {
    
        // create a marker
        var newMarker = new Marker(e.nodeindex, e.plotindex);
    
        markerHashTable['plotindex_' + e.plotindex][e.nodeindex] = true;
        markersArray.push(newMarker);
    
        // render the marker
        myConfig.scaleX.markers = markersArray;
        zingchart.exec('myChart', 'setdata', {
          data: myConfig
        });
      }
    
    });