0

Currently looking at Providing Chart Data Using a JavaScript Function

The chart is not rendering for me; not at all, though I have confirmed that the JavaScript getRemoteData() method is attempted.

Using Chrome's debugger, I managed to find

Visualforce Chart: Error loading configuration for chart 'jid0jid2': VF_PieChartVFCtrl is not defined

Here is my VisualForce page:

   <apex:page >
    <script>
        function getRemoteData(callback) 
        {
            VF_PieChartVFCtrl.getRemotePieData(function(result, event) 
            {
               if(event.status && result && result.constructor === Array) 
               {
                   callback(result);
               }
           });
        }
    </script>
    <apex:chart height="350" width="450" data="getRemoteData">
        <apex:pieSeries dataField="data" labelField="name" />
        <apex:legend position="right" />
    </apex:chart>
</apex:page>

What do I need to add to get my browser to communicate with the controller?

If it makes any difference, my organization has a namespace ("Sledgehammer"), but neither

  • Sledgehammer.VF_PieChartVFCtrl.getRemotePieData(function(result, event)
  • Sledgehammer__VF_PieChartVFCtrl.getRemotePieData(function(result, event)

seemed any more effective.

1

First, you need to assign the class that houses the function to your page. Use either the controller attribute, or the extensions attribute if you need to mix in multiple controllers. Also, if you're in an iframe, you also need to make the class global. Finally, use the $RemoteAction global variable to automatically reference your call correctly. See the documentation for example code.

  • I'm not sure I follow. The example on the "Providing Chart Data Using a JavaScript Function" documentation I linked to does not seem to include this, but made it seem much simpler... currently seeing if the page you referred to can help out... – Brian Kessler Nov 20 '14 at 15:37
0

Not sure why it didn't work before, but I added the namespace (again) and this works now:

<apex:page controller="VF_PieChartVFCtrl">
<script>
    function getRemoteData(callback) 
    {
        Sledgehammer.VF_PieChartVFCtrl.getRemotePieData(function(result, event) 
        {
           if(event.status && result && result.constructor === Array) 
           {
               callback(result);
           }
       });
    }
</script>
<apex:chart height="350" width="450" data="getRemoteData">
    <apex:pieSeries dataField="data" labelField="name" />
    <apex:legend position="right" />
</apex:chart>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.