ChartJs with dynamic dataset

0

I need to create a dynamic dataset where the data will be filled through a query in the database, this data can generate N bars to be plotted so the dataset needs to be created according to the information coming from DB .

The number of bars you create also depends on the query. It will look like this:

Data 1-> barra 1
Data 2 -> barra 2
Data 3 -> barra 3
Data 1(horario diferente, mesmo ID) -> barra 4....

I'm using chartsjs to plot.

    
asked by anonymous 27.03.2018 / 19:10

1 answer

0

Create a vector with the information returned in the database and include the vector in the parameters of the dataset.

var data[]; 
var valores[];
//data e valores virão do seu banco.

this.barChart = new Chart(this.barCanvas.nativeElement, {
type: 'bar',
data: {
    labels: "Nome do gráfico",
    datasets: [{                
        label:data,
        data: valores,
        backgroundColor: #00000,
        borderWidth: 0                
    }]
}
    
17.05.2018 / 19:52