• 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></style>
    </head>
    
    <body>
      <div id='myChart'></div>
      <script>
        ZC.LICENSE = ["569d52cefae586f634c54f86dc99e6a9", "b55b025e438fa8a98e32482b5f768ff5"]; // Global wrapper
        window.customFncs = {};
    
        var myConfig = {
          type: "line",
          title: {
            text: 'Custom Tooltip History'
          },
          tooltip: {
            jsRule: "window.customFncs.formatTooltip()"
          },
          series: [{
              values: [1, 3, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4]
            },
            {
              values: [6, 7, 8, 7, 6, 7, 8, 9, 8, 7, 8, 7, 8, 9, 8]
            }
          ]
        };
    
        // simple associative array
        var tooltipHistoryHash = [];
    
        /*
         * Function under our ZC wrapper. Will
         * be fired when the node is hovered over
         *
         * @param {object} p ZingChart callback argument. 
         * is associated to various graph properties
         */
        window.customFncs.formatTooltip = function(p) {
          console.log(p);
          var plotIndex = p.plotindex;
          var nodeIndex = p.nodeindex;
          var hashId = 'p:' + plotIndex + 'n:' + nodeIndex;
          var tooltipText = "";
    
          // Simple logic, if exists grab the value. Else let user
          // know its the first time
          if (tooltipHistoryHash[hashId]) {
    
            // Get the time elapsed since the last hover
            var elapsed = Math.floor((new Date().getTime() - tooltipHistoryHash[hashId]) / 1000);
            tooltipText = "Last Time Hovered: ";
    
            // If it's less than 0, they hovered less than a second ago
            if (elapsed === 0) {
              tooltipText += "less than a second ago!";
            } else {
              tooltipText += elapsed.toString() + " seconds ago";
            }
    
          } else {
            tooltipText = "First Time Hovering!";
          }
    
          // Assign into associative array (hash)
          tooltipHistoryHash[hashId] = new Date().getTime();
    
          // Return and object with multiple properties
          return {
            text: tooltipText,
            backgroundColor: "#222"
          }
        }
    
        zingchart.render({
          id: 'myChart',
          data: myConfig,
          height: 400,
          width: 600
        });
      </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>
    
          
    // Global wrapper
    window.customFncs = {};
    
    var myConfig = {
      type: "line",
      title: {
        text: 'Custom Tooltip History'
      },
      tooltip: {
        jsRule: "window.customFncs.formatTooltip()"
      },
      series: [{
          values: [1, 3, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4]
        },
        {
          values: [6, 7, 8, 7, 6, 7, 8, 9, 8, 7, 8, 7, 8, 9, 8]
        }
      ]
    };
    
    // simple associative array
    var tooltipHistoryHash = [];
    
    /*
     * Function under our ZC wrapper. Will
     * be fired when the node is hovered over
     *
     * @param {object} p ZingChart callback argument. 
     * is associated to various graph properties
     */
    window.customFncs.formatTooltip = function(p) {
      console.log(p);
      var plotIndex = p.plotindex;
      var nodeIndex = p.nodeindex;
      var hashId = 'p:' + plotIndex + 'n:' + nodeIndex;
      var tooltipText = "";
    
      // Simple logic, if exists grab the value. Else let user
      // know its the first time
      if (tooltipHistoryHash[hashId]) {
    
        // Get the time elapsed since the last hover
        var elapsed = Math.floor((new Date().getTime() - tooltipHistoryHash[hashId]) / 1000);
        tooltipText = "Last Time Hovered: ";
    
        // If it's less than 0, they hovered less than a second ago
        if (elapsed === 0) {
          tooltipText += "less than a second ago!";
        } else {
          tooltipText += elapsed.toString() + " seconds ago";
        }
    
      } else {
        tooltipText = "First Time Hovering!";
      }
    
      // Assign into associative array (hash)
      tooltipHistoryHash[hashId] = new Date().getTime();
    
      // Return and object with multiple properties
      return {
        text: tooltipText,
        backgroundColor: "#222"
      }
    }
    
    zingchart.render({
      id: 'myChart',
      data: myConfig,
      height: 400,
      width: 600
    });