Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

    Code Block
    <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.

    Image Modified

  3. Add the JavaScript from the Google line chart example

    Code Block
    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.

    Code Block
    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.

...

  1. Image Added
Note

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

...

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

Filter by label (Content by label)
showLabelsfalse
max5
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@135a7
sortmodified
showSpacefalse
reversetrue
typepage
cqllabel = "kb-how-to-article" and type = "page" and space = "PKB"
labelskb-how-to-article

...