Skip to end of banner
Go to start of banner

Using the D3.js Library with Power Dashboard Reports and Gadgets

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

How to add the D3.js library to Power Dashboard Reports and Gadgets. In this example, we will be following this line chart example from Google.

Instructions

  1. Copy the body html from the Google line chart example, add it to a file in the “silprograms” file that ends with “.tpl”. Add “html” tags as pictured below.

    <html>
      <body>
        <div id="curve_chart" style="width: 900px; height: 500px"></div>
      </body>
    </html>

  2. Create a new SIL Reporting Gadget, select the .tpl file you just created.

  3. Add the JavaScript from the Google line chart example

    google.charts.load('current', {'packages':['corechart']});
    google.charts.setOnLoadCallback(drawChart);
    
    function drawChart() {
      var data = google.visualization.arrayToDataTable([
        ['Year', 'Sales', 'Expenses'],
        ['2004',  1000,      400],
        ['2005',  1170,      460],
        ['2006',  660,       1120],
        ['2007',  1030,      540]
      ]);
    
      var options = {
        title: 'Company Performance',
        curveType: 'function',
        legend: { position: 'bottom' }
      };
    
      var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
    
      chart.draw(data, options);
    }

  4. Add the following at the end of the JavaScript so that it loads the D3.js library.

    var script = document.createElement('script');
    script.src = "https://www.gstatic.com/charts/loader.js";
    document.body.appendChild(script);

  5. Toggle on the “Use custom javascript file?” and select the javascript file created in the previous step.

Make sure that the script created in step 1 ends in .tpl, or the chart will not render properly

After clicking on the “Save” button, the chart should look like this:

Additional Help

Need help implementing this script? Talk to me directly to me by clicking on the bot on bottom of our appfire.com page.

Filter by label

There are no items with the selected labels at this time.

  • No labels