3👍
✅
The most easy way to do this is to insert the values in array.
<script>
var labels = [];
@foreach(var label in ViewBag.ChartLabel)
{
<text>
labels.push('@label');
</text>
}
</script>
You can find here more ways to convert, the one that I think it’s the best
var labels = @Html.Raw(Json.Encode(ViewBag.ChartLabel));
Source:stackexchange.com