<script>
const labels = [
'Male',
'Female',
];
var count = 0;
@{
var count=0;
foreach (var Data in Model)
{
if (@Data.PersonGender=="Male")
{
count += 1;
};
}
}
const data = {
labels: labels,
datasets: [{
data: [count, 8],
}]
};
const config = {
type: 'pie',
data: data,
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
}
},
};
I am trying to use same variable but I can't. My main goal is to show the ratio of the genders of the objects in the list that I created from the SQL table as a pie chart. I think count is calculated correctly but I can't use the variable inside @{} outside.