• Surya V 2
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi All,
How to call javascript in visualforce page using static resource?
 
Trying to include javascript in visualforce but i'm not getting proper output. Please find the below code.
This code is woking fine now, but i need to call javascript alone in visualforce page through static resource.
I need to call highlighted javascript code in static resource.
===================================================================================
<apex:page standardController="Inquiry__c" sidebar="false">
<head>
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"></meta>
</head>
<!-- <apex:includeScript value="{!URLFOR($Resource.JSforce)}" /> Static Resource or Direct Link Below -->
<!--<script src="//cdnjs.cloudflare.com/ajax/libs/jsforce/1.4.1/jsforce.min.js"></script>-->  <!-- Direct Link For the Script File  -->
<script src="{!$Resource.jsforce_30}"></script>
<!--<script type="text/javascript" src="https://www.google.com/jsapi"></script>-->
<script src="{!$Resource.jsapi_30}"></script>
<apex:outputPanel >
<div>
<table>
<tr>
<td>
    <div id="barChart" style="width: 460px; height: 250px;"></div></td>
  <td>  <div id="pieChart" style="width: 450px; height: 250px;"></div></td>
  </tr>
    </table>
</div>
</apex:outputPanel>
<script>
var cArr = [];
var cArr1 = [];
var conn = new jsforce.Connection({ accessToken: '{!$Api.Session_Id}' });
conn.query("select  Status,count(id),whatid from Task where whatid= '{!Inquiry__c.id}' group by Status,whatid ", function(err, res) {
if (err) { return console.error(err); }
  
   for(i = 0; i < res.records.length; i++)
   {
        cArr.push(res.records[i].Status);
        cArr1.push(res.records[i].expr0);
      
   }
});
  
google.load("visualization", "1.1", {packages:["bar", "corechart"]});
google.setOnLoadCallback(drawStuff);
      
function drawStuff() {
       //adding columns to Google DataTable
         var data = new google.visualization.DataTable();
            data.addColumn('string','Status');
            data.addColumn('number','Total Task');
         
for(i = 0; i < cArr1.length; i++)
    data.addRow([cArr[i], cArr1[i]]);
    
var options = {
        
        bars: 'vertical', // Required for Material Bar Charts.
        axes: {
            x: {
              0: { side: 'left', label: 'Status'}
            },
            y: {
              0: { label: 'Number Of Task'} 
            }
          },
          bar: { groupWidth: "5%" }
      };
        
//-----Drawing Charts-----
//BarChart
var chart = new google.charts.Bar(document.getElementById('barChart'));
        chart.draw(data, options);
        
 
           
      };
      
</script>
</apex:page>
=================================================================================
 
Thanks in advance.
I have built the reports and dashboards as outlined in the requirements, but I'm getting the following error "Challenge Not yet complete... here's what's wrong: Couldn't find a component with the title 'My Top Accounts'."  
User-added image

However, I have the component on the dashboard as you can see below.
User-added image
What am I missing?