I am trying to make a Chart with Chart.js but i cant get the data from my model into the chart... can someone help me with this?
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<canvas id="myChart" width="400" height="400"></canvas>
<script >
var ctx = document.getElementById('myChart').getContext('2d');
@{
List<String> listKeys = new List<string>();
List<int> listValues = new List<int>();
foreach(var x in Model.PageViews)
{
listKeys.Add(x.Key + "");
listValues.Add(x.Value);
}
}
var chart = new Chart(ctx, {
type: 'line',
data: {
labels: @listKeys,
datasets: [{
label: "My First dataset",
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: @listValues
}]
},
options: {}
});
I've tried multiple things but nothing seems to work...
IEnumerable<string> LabelsandIEnumerable<int> Valuesand then you usevar labels = @Html.Raw.Json.Encode(Model.Labels))ect to convert the model to a javascript array