Saturday 2 January 2016

How to use Highcharts Pie graph in Asp.net

Check previous post here Create a Monthly Average Rainfall graph of Highcharts Basic column in Asp.Net , Introduction to Angular JS.

Following are the basic steps to use highcharts Pie graph.

Step 1:

 a. Add jQuery library in Head section of your page.

Google CDN:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
OR 
Microsoft CDN:
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js"></script>

b. Add Highcharts library to use different  highcharts graph.   

    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/exporting.js"></script>

 Step 2: 

        Add a div in your page to display the highcharts Pie graph.

       <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

Step 3:

       Add a jquery function to load the graph in div of your page.

<script type="text/javascript">
          $(function () {

              $(document).ready(function () {
                      var chart = new Highcharts.Chart({
                  // Build the chart
                  
                      chart: {
                          plotBackgroundColor: null,
                          plotBorderWidth: null,
                          plotShadow: false,
                          type: 'pie',
                          renderTo: 'container'
                      },
                      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>

Output :



No comments:

Post a Comment

Join US Our Community
×