JSChart Custom Component

For more options on custom charts, here is a walkthrough on how you can complete this JSChart.

  • Not yet re-checked
  • Classic builder

Moved from our previous help site and not yet re-checked against the current product. Last edited Sep 20, 2024.

Screenshot for “JSChart Custom Component”

For more options on custom charts, here is a walkthrough on how you can complete this JSChart.

Step 1

Add the ChartJS CDN code to the header of your app.

Text
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.0/chart.min.js" integrity="sha512-TW5s0IT/IppJtu76UbysrBH9Hy/5X41OTAbQuffZFU6lQ1rdcLHzpU5BzVvr/YFykoiMYZVWlr/PX1mDcfM9Qg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Screenshot for “JSChart Custom Component”

Step 2

Add a Custom Component. Add the following settings in calculations in the Data Source of the component.

Screenshot for “JSChart Custom Component”

Step 3

In your custom component template tab, add the following code.

Text
{{#each records}}
    <div class="hide">
        <h1><div id="totalRecords">{{total}}</div></h1>
        <h1><div id="maxRecords">{{max}}</div></h1>
        <h1><div id="minRecords">{{min}}</div></h1>
    </div>
{{/each}}

<div>
  <canvas id="myChart"></canvas>
</div>
Screenshot for “JSChart Custom Component”

Step 4

Add the following code to the JavaScript tab within your custom component.

Text
$(document).ready(function() {
    var total = $("#totalRecords").html();
    var max = $("#maxRecords").html();
    var min = $("#minRecords").html();

    new Chart(document.getElementById("myChart"), {
        type: 'bar',
        data: {
            labels: ["Total", "Max", "Min"],
            datasets: [{
                label: "Totals",
                backgroundColor: ["#3e95cd", "#8e5ea2", "#3cba9f"],
                data: [total, max, min]
            }]
        }
    });

});
Screenshot for “JSChart Custom Component”

Original Community Post:

Add record values on the javascript tab of a custom component - Community Discussions / How Do I - Tadabase Community

Was this page helpful?

Something wrong or missing on this page? Tell us.