Highcharts - making the values dynamic instead of static

自闭症网瘾萝莉.ら 提交于 2019-12-13 05:14:11

问题


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 .Have uploaded the picture where bar/column chart doesn't show up and line chart shows where values are declared..Kindly help.

      <!-- 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.

来源:https://stackoverflow.com/questions/24683498/highcharts-making-the-values-dynamic-instead-of-static

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!