Issue with data for bar chart in a graph - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
James josephJames joseph 

Issue with data for bar chart in a graph

Have created a graph which includes bar chart with plotted lines and pie chart in it. I'm trying to fetch values dynamically for bar chart but it is not displaying Kindly help.Pressing my head but no luck .I really need help from the community.


      <!-- Vf page-->
      <apex:page controller="HighchartsController">

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

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

        <script>
             $(function () {
             $('#container').highcharts({
             title: {
             text: 'Chart showing opportunities'
        },
        xAxis:{
                categories: ['Jan','Feb','Mar','Apr','May']
            },
              labels: {
              items: [{
              html: 'Opportunities',
              style: {
                    left: '50px',
                    top: '18px',
                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
                }
            }]
        },
        series: [ {
            type: 'column',
            name: 'Indian Railways',
            data: "[{!nvs}]"   // values coming from controller and here i need to fetch it.
        },
         {
            type: 'spline',
            name: 'Monthly Sales', // Average
            data: [3, 2.67, 3, 6.33, 3.33],  
            marker: {
                lineWidth: 2,
                lineColor: Highcharts.getOptions().colors[3],
                fillColor: 'white'
            }
        },
        {
            type: 'pie',
            name: 'Total consumption',
            data: [ {
                name: 'Lost',
                y:23,
           
                sliced:true,
                selected:true,
                color: Highcharts.getOptions().colors[1] // Opp's Lost color
              },
             {
                name: 'Won',
                 y:19,
             
                color: Highcharts.getOptions().colors[2] // Opp's won color
              }],
               center: [100, 80],
               size: 100,
               showInLegend: false,
               dataLabels:
               {
                 enabled:true
               }
           }]
       });
   });
    </script>
    </apex:page>

 
       //Apex class
  
    
              
       public class HighchartsController
      { 
           // for bar chart
           // N for name , v for data
          public class Nv {
             public String n { get; private set; }       
             public integer v { get; private set; }
                Nv(String n,Integer v) {
                 this.n = n;
                 this.v = v;      
            } 
         }
      public Nv[] getnvs() {
        return new Nv[] {
            new Nv('Jan',5),
            new Nv('Feb',45),
            new Nv('Mar',35),
            new Nv('Apr',25) ,     
            new Nv('may',15)
          };
        }
      }

    
Highly appreciate the help.
    


 
Michael GillMichael Gill
Post this over on developer boards and SE if urgent. Is this everything I need to run in my own org?

https://developer.salesforce.com/forums/#!/feedtype=RECENT&criteria=ALLQUESTIONS&

http://salesforce.stackexchange.com/
James josephJames joseph
Yes, this is everything that you need to run . Simply copy and paste and you would see the result  and will better understand my question . This is really urgent .

Also i've posted this question on Stackexchange , but no luck..:(  Really pressing my head hard.
Link : http://salesforce.stackexchange.com/questions/43804/how-to-get-data-dynamically-instead-of-static-data