DocRaptor HTML TO PDF API

Code Examples: Highcharts Pie Chart

Here's how to make a PDF with DocRaptor that contains a Highchart Pie Chart:

<html>
  <!-- One of many ways to make sure the chart fits on the page -->
  <style type="text/css">
    @page { 
      prince-shrink-to-fit: auto; /* sizes entire document to contents of first page*/
    }
  </style>

  <body>    
    <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/exporting.js"></script>

    <!-- Highcharts demo code taken from http://www.highcharts.com/demo/line-labels -->
    <script>
      $(document).ready(function () {
       
          // Build the chart
          Highcharts.chart('container', {
              chart: {
                  plotBackgroundColor: null,
                  plotBorderWidth: null,
                  plotShadow: false,
                  type: 'pie'
              },
              title: {
                  text: 'Browser market shares January, 2015 to May, 2015'
              },
              tooltip: {
                  pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
              },
              plotOptions: {
                  pie: {
                      allowPointSelect: true,
                      cursor: 'pointer',
                      dataLabels: {
                          enabled: false
                      },
                      showInLegend: true
                  }
              },
              series: [{
                  name: 'Brands',
                  colorByPoint: true,
                  data: [{
                      name: 'Microsoft Internet Explorer',
                      y: 56.33
                  }, {
                      name: 'Chrome',
                      y: 24.03,
                      sliced: true,
                      selected: true
                  }, {
                      name: 'Firefox',
                      y: 10.38
                  }, {
                      name: 'Safari',
                      y: 4.77
                  }, {
                      name: 'Opera',
                      y: 0.91
                  }, {
                      name: 'Proprietary or Undetectable',
                      y: 0.2
                  }]
              }]
          });
      });
    </script>

    <!-- Highcharts often waits long enough that DocRaptor thinks the javascript is finished -->
    <!-- when it is not. -->
    <!-- This function tells the DocRaptor javascript engine to wait 3 seconds before finishing. -->
    <!-- https://docraptor.com/documentation/api#api_javascript -->
    <script>
      var didWait = false;
      // DocRaptor polls docraptorJavaScriptFinished until it is true
      docraptorJavaScriptFinished = function() {
        if (! didWait) {
          setTimeout(function(){
            didWait = true;
          }, 3000);
          return false;
        }
        return true;
      }
    </script>

    <!-- Container for chart -->
    <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
  </body>
</html>

Ready to get started? Try DocRaptor for free with unlimited test documents.