0

I have some VF's which there they have their own jS being executed. When I had embed these pages as apex:tabs and tried navigate through them the jS apparently aren't being executed.

Even when I used only one of these pages as tab the error persisted. The page loads and execute correctly if accessed outside of apex:tab. Another attempt was include the main JS (static resource, but no success).

Web console error:

Uncaught TypeError: Cannot set property 'x-axis-0' of undefined
at Chart.js:4086
at Object.each (Chart.js:9899)
at Chart.buildOrUpdateScales (Chart.js:4077)
at Chart.initialize (Chart.js:3967)
at Chart.construct (Chart.js:3943)
at new Chart (Chart.js:6215)
at showDashboard (HotelMasterSelectionPage?sfdc.tabName=01r3E000000DeWS&core.apexpages.devmode.url=1:164)
at initialize (HotelMasterSelectionPage?sfdc.tabName=01r3E000000DeWS&core.apexpages.devmode.url=1:136)

Note: Using the property switchType as ajax or client the execution didn't work.

Update 23/05: I had debugged the JS and discovered that the data is being retrieved, although an internal function is failing without reason.

Update 24/05: Removed all logic and hardcoded the code it seems the error only appear when we use a apex:tag to embed the Visualforce. For tests you must download the ChartJS API or access as external source.

Code Sample VF

<apex:page id="page" controller="myController" sidebar="false">
<apex:includeScript value="{!URLFOR($Resource.ChartJS, 'Chart.js')}"/>

<apex:form >
    <body>    
        <script>

        window.onload = function() {
        var ctx = document.getElementById("myChart").getContext("2d");

        var myChart = new Chart(ctx, {
            type: 'bar',
            data: {
                labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
                datasets: [{
                    label: '# of Votes',
                    data: [12, 19, 3, 5, 2, 3],
                    backgroundColor: [
                        'rgba(255, 99, 132, 0.2)',
                        'rgba(54, 162, 235, 0.2)',
                        'rgba(255, 206, 86, 0.2)',
                        'rgba(75, 192, 192, 0.2)',
                        'rgba(153, 102, 255, 0.2)',
                        'rgba(255, 159, 64, 0.2)'
                    ],
                    borderColor: [
                        'rgba(255,99,132,1)',
                        'rgba(54, 162, 235, 1)',
                        'rgba(255, 206, 86, 1)',
                        'rgba(75, 192, 192, 1)',
                        'rgba(153, 102, 255, 1)',
                        'rgba(255, 159, 64, 1)'
                    ],
                    borderWidth: 1
                }]
            },
            options: {
                scales: {
                    yAxes: [{
                        ticks: {
                            beginAtZero:true
                        }
                    }]
                }
            }
        });

            }
        </script>

        <apex:pageBlock id="mainpanel"> 
            <apex:outputPanel>
                <apex:outputText value="VF Test" style="font-size: 20px; text-align: center;"   />
                <hr/>
                <div style="width: 80%;">
                    <canvas id="myChart" width="400" height="400"></canvas>
                </div>                

            </apex:outputPanel>
        </apex:pageBlock>
    </body>
</apex:form>

Main

<apex:page showHeader="true" lightningStylesheets="true" title="MyTest">

<apex:pageBlock >
    <apex:tabPanel >
        <apex:tab label="TestChartJS" name="" id="TestChartJS">
            <apex:include pageName="testChartJS"/> 
        </apex:tab>
    </apex:tabPanel>
</apex:pageBlock>

  • can you add your VF code where the script is included – alphaBytes May 23 '18 at 15:47
  • @alphaBytes code added. – Carlos May 24 '18 at 11:14

Your Answer

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

Browse other questions tagged or ask your own question.