Give Foreach a label in Chartjs / Canvas - CodeIgniter

0

I have a problem here, which may be simple, I do not know I'm using a graphic frame, where I can put the labels I want so it can be displayed at each bar. Staying like this:

Eachitem(January,February,March...correspondstoalabelinthefollowingcode:

vardata={labels:["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],

I'm wanting to get these labels through the database I use, and even I do this normally, and display array normally. However, I'm trying the following code:

var data = {
            labels: ["<?php foreach ($fase as $fase){ echo $fase->nomefase;} ?>"],
            datasets: [

The problem with this code is that I can not insert a comma to separate the array items I'm looking for from the database. At the time of entering the comma, foreach ends, and starts again, causing me to display no items, or if I only have one item in array , it displays the first and only.

I tried to break several times in fragments and tried so hard to make it work, but it gives error.

    
asked by anonymous 28.10.2016 / 21:44

2 answers

3

Instead of creating the javascript array structure in hand, let json_encode() do This is for you. Just create the list of names and let the function print the formatted array:

labels: <?php foreach ($fase as $f) { $labels[] = $f->nomefase; } echo json_encode( $labels );  ?>,
    
29.10.2016 / 04:39
0

In the University CodeIgniter portal there is an article showing the use of ChartJS with CodeIgniter.

link

    
08.11.2016 / 20:21