I need to make a dashboard and I'm having a hard time getting a line graph of a graphic canvas.
I need the data and label arrays to be populated with the data in my list but I do not know how to do it.
What do I need to do to achieve this?
<script>
var ctx = document.getElementsByClassName("line-chart");
var teste = new Chart(ctx, {
type: 'line',
data: {
labels: ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"],
datasets: [{
label: "taxa de cliques 2017",
data: [5, 10, 15, 12, 20, 30, 8, 7, 2, 3, 6, 1],
borderWidth: 6,
borderColor: 'rgba(77,166,253,0.85)',
backgroundColor: 'transparent',
},
{
label: "taxa de cliques 2017",
data: [8, 11, 13, 2, 80, 40, 84, 71, 22, 43, 46, 11],
borderWidth: 6,
borderColor: 'rgba(6,204,6,0.85)',
backgroundColor: 'transparent',
}]
},
options: {
title: {
display: true,
fontSize: 20,
text: "Relatorio de CTR anual"
},
labels: {
fontStyle: "bold",
}
}
})
</script>
My project is with the Chart.JS version referenced below
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
MyconnectionisinSQL,Imadeamethodtopopulatealistfromaselect...IgettheList<>IjustdonotknowhowtotransferthisdatatoJS
Follow
//methodthatiscalledfromthecontroller
publicvoidteste(List<Pessoa>lista){SqlConnectionconnection=newSqlConnection("DBConecction");
connection.Open();
SqlCommand command = new SqlCommand(SQL(), connection);
var datatable = new DataTable();
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = command;
DA.Fill(datatable);
foreach (DataRow row in datatable.Rows)
{
lista.Add(new Pessoa { dia = Convert.ToInt32(row["dia"]), peso = Convert.ToDouble(row["peso"]) });
}
}
// SQL string
public string SQL()
{
string sSQL = "select day(data_entrega) 'dia' " +
",sum(peso_roadnet) 'peso' " +
"from ConsultaFreteRot2 " +
"where DATA_ENTREGA between '2018-03-01' " +
" and '2018-03-28' " +
"group by day(DATA_ENTREGA) " +
"order by dia";
return sSQL;
}
NOTE: I am not using the Entity Framework in the project