Clive-S free asked 6 years ago


Greetings,

 

I have a Table that has Cluster 1 - Cluster 5.

Each Cluster has the following records: Budgeted and Allocated.

// Current table (below)

Cluster              Budgeted ( { a.budgeted } )    Allocated ( { a.allocated } )
Cluster 1                 1                                                     0
Cluster 2               4                                                      0
Cluster 3               5                                                      3
Cluster 4               0                                                     0
Cluster 5               0                                                     0

 

I cannot see how to place the "loop" - {% for a in allocations %} within the dataset (the chart example which is hard-coded).

I want to replace >> data: [12, 19]  in //Bootstrap.js  with data: [ {{ a.budgeted }}, {{ a.allocated }}] from //Current table

Any assistance is appreciated.

Code for Table above:

// Current table
<div class="panel panel-primary">
<div class="panel-heading">Budgeted FTE and Allocated FTE </div>
<div class="panel body">
{% if allocations %}
<table>
<thead>
<th>Cluster</th>
<th class="midc">Budgeted FTE</th>
<th>Allocated FTE</th>
</thead>
{% for a in allocations %}
<tr>
<td>Cluster {{ a.id }}</td>
<td class="midc">{{ a.budgeted }}</td>
<td>{{ a.allocated }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
</div>

 

 

// Bootstrap.js

<canvas id="barChart"></canvas>

//bar chart
var ctxB = document.getElementById("barChart").getContext('2d');
var myBarChart = new Chart(ctxB, {
type: 'bar',
data: {
labels: ["Budgeted FTE", "Allocated FTE" ],
datasets: [{
label: '# Budgeted FTE ',
data: [12, 19],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});

 


Jakub Strebeyko staff answered 6 years ago


Hi there Clive, Thanks for reaching out! The chart takes JavaScript as input, so that's the first thing to consider. The rest (method of data conversion) depends on your technology stack, so that's the question of what are you using for your project and how can you integrate it into chart data input pattern. It could involve a dynamically generated JS script embedded into HTML, initializing the graph with appropriate data. Hope it is of any help. With Best Regards, Kuba

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: General Bootstrap questions
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: Yes
  • Provided link: No
Tags