Activity Forums Salesforce® Discussions How we can create google chart from apex class in Salesforce?

  • How we can create google chart from apex class in Salesforce?

  • Nikita

    Member
    December 6, 2019 at 8:36 am

    How we can create google chart from apex class in Salesforce?

  • Deepak

    Member
    December 6, 2019 at 12:34 pm

    <apex:page >
    <apex:includeScript id="a" value="https://www.google.com/jsapi" />
    <apex:sectionHeader subtitle="Reactive Call Outs Per Day"/>
    <!-- Google Charts will be drawn in this DIV -->
    <div id="chart_div" />

    <script type="text/javascript" src="/soap/ajax/20.0/connection.js"></script>
    <script type="text/javascript">
    sforce.connection.sessionId = "{!$Api.Session_ID}";
    var result = sforce.connection.query("SELECT DAY_ONLY(CreatedDate) days, count(createdDate) counts FROM Visits__c where createdDate = LAST_N_Days:90 GROUP BY DAY_ONLY(CreatedDate) order by DAY_ONLY(createdDate) desc");
    records = result.getArray("records");
    // Load the Visualization API and the piechart package.
    google.load('visualization', '1.0', {'packages':['corechart']});
    google.setOnLoadCallback(drawCharts);
    function drawCharts() {
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Created Date');
    data.addColumn('number', 'Record Count');
    data.addRows(records.length);
    for(var i = 0 ; i < records.length ; i++){
    data.setValue(i,0,records[i].days);
    data.setValue(i,1,records[i].counts);
    }
    var options = {
    title: '',
    hAxis: {title: 'days'},
    vAxis: {title: 'counts'},
    legend: 'none',
    trendlines: { 0: {color: 'red',} } // Draw a trendline for data series 0.
    };
    var visualization = new google.visualization.ColumnChart(document.getElementById('chart_div'));
    visualization.draw(data,options);
    }
    </script>
    </apex:page>

Viewing 1 - 2 of 2 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos

Pros & Cons of Lightning Component vs. 3rd party frameworks in Salesforce UI development

Video in

Nikita drops by to share his invaluable experience of using popular 3rd party frameworks in Salesforce. http://media.blubrry.com/salesforceway/audio.xmcdn.com/group42/M05/25/57/wKgJ81rXk6XjaZIAAU_I_KtprFM998.m4a