Render Highchart in jQuery tooltip - Javascript highcharts

Javascript examples for highcharts:Chart Tooltip

Description

Render Highchart in jQuery tooltip

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>jQuery Tooltip</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
      <script type="text/javascript" src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
      <link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css"> 
      <style id="compiled-css" type="text/css">

label {//from   www .  j  av  a  2 s .co  m
   display: inline-block;
   width: 5em;
}
.ui-tooltip {
   position: absolute;
   background: #f9a235;
   color: #fff;
   padding: 6px 0px;
   border-radius: 25px;
}


      </style> 
      <script type="text/javascript">
    $(window).load(function(){
$(function() {
  $(document).tooltip({
    open: function(event, ui) {
      ui.tooltip.find("[data-chart='chart']").highcharts({
        chart: {
          type: 'bar'
        },
        title: {
          text: 'Historic World Population by Region'
        },
        subtitle: {
          text: 'Source: <a href="https://en.wikipedia.org/wiki/World_population">Wikipedia.org</a>'
        },
        xAxis: {
          categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
          title: {
            text: null
          }
        },
        yAxis: {
          min: 0,
          title: {
            text: 'Population (millions)',
            align: 'high'
          },
          labels: {
            overflow: 'justify'
          }
        },
        tooltip: {
          valueSuffix: ' millions'
        },
        plotOptions: {
          bar: {
            dataLabels: {
              enabled: true
            }
          }
        },
        legend: {
          layout: 'vertical',
          align: 'right',
          verticalAlign: 'top',
          x: -40,
          y: 80,
          floating: true,
          borderWidth: 1,
          backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
          shadow: true
        },
        credits: {
          enabled: false
        },
        series: [{
          name: 'Year 1800',
          data: [107, 31, 635, 203, 2]
        }, {
          name: 'Year 1900',
          data: [133, 156, 947, 408, 6]
        }, {
          name: 'Year 2012',
          data: [1052, 954, 4250, 740, 38]
        }]
      });
    }
  });
});
    });

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/modules/exporting.js"></script> 
      <p> 
         <label for="age">Your age:</label> 
         <input id="age" title="<div data-chart='chart' style='width:500px;height:500px;background:red;border:5px solid blue;border-radius:10px;'></div>"> 
      </p> 
      <p>Hover the field to see the tooltip.</p> 
      <!-- Post Info --> 
      <div style="position:fixed;bottom:0;left:0;
            background:lightgray;width:100%;">
          About this SO Question: 
         <a href="http://stackoverflow.com/q/23498641/1366033">How do I make rounded Jquery UI tooltips?</a>
         <br>
          Documentation: 
         <a href="http://jqueryui.com/tooltip/">jQuery - UI - Tooltips</a>
         <br> 
         <div>  
         </div>
      </div>
   </body>
</html>

Related Tutorials