Adding pie chart to stats
This commit is contained in:
@@ -99,6 +99,25 @@ namespace pointMaster.Controllers
|
|||||||
return Ok(JsonConvert.SerializeObject(vm));
|
return Ok(JsonConvert.SerializeObject(vm));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Route("pointratio")]
|
||||||
|
public async Task<IActionResult> GetPointRatio()
|
||||||
|
{
|
||||||
|
var vm = new PointRatioModel();
|
||||||
|
|
||||||
|
vm.Names = new List<string>();
|
||||||
|
vm.Data = new List<int>();
|
||||||
|
|
||||||
|
var data = await dataContext.Patruljer.Include(x => x.Points).ToListAsync();
|
||||||
|
|
||||||
|
foreach (var patrulje in data)
|
||||||
|
{
|
||||||
|
vm.Names.Add(patrulje.Name);
|
||||||
|
vm.Data.Add(patrulje.Points.Sum(x => x.Points + x.Turnout));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(JsonConvert.SerializeObject(vm));
|
||||||
|
}
|
||||||
|
|
||||||
public class PointChartModel
|
public class PointChartModel
|
||||||
{
|
{
|
||||||
[JsonProperty("name")]
|
[JsonProperty("name")]
|
||||||
@@ -117,5 +136,13 @@ namespace pointMaster.Controllers
|
|||||||
public string Title { get; set; } = null!;
|
public string Title { get; set; } = null!;
|
||||||
public string Value { get; set; } = null!;
|
public string Value { get; set; } = null!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class PointRatioModel
|
||||||
|
{
|
||||||
|
[JsonProperty("names")]
|
||||||
|
public List<string> Names { get; set; } = null!;
|
||||||
|
[JsonProperty("data")]
|
||||||
|
public List<int> Data { get; set; } = null!;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,8 @@
|
|||||||
<div class="stat-chart">
|
<div class="stat-chart">
|
||||||
<p class="stat-title">Point over tid</p>
|
<p class="stat-title">Point over tid</p>
|
||||||
<div id="chart"></div>
|
<div id="chart"></div>
|
||||||
|
<p class="stat-title">Point ratio</p>
|
||||||
|
<div id="pie"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -41,7 +43,7 @@ export default defineComponent({
|
|||||||
chart: {
|
chart: {
|
||||||
type: "line",
|
type: "line",
|
||||||
toolbar: {
|
toolbar: {
|
||||||
show: false,
|
show: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
xaxis: {
|
xaxis: {
|
||||||
@@ -63,9 +65,35 @@ export default defineComponent({
|
|||||||
} as ApexOptions);
|
} as ApexOptions);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const initializePieChart = async () => {
|
||||||
|
const options: ApexOptions = {
|
||||||
|
chart: {
|
||||||
|
type: "pie",
|
||||||
|
toolbar: {
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
series: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const chart = new ApexCharts(
|
||||||
|
document.querySelector("#pie"),
|
||||||
|
options
|
||||||
|
);
|
||||||
|
chart.render();
|
||||||
|
|
||||||
|
const data = (await axios.get("/api/pointratio")).data;
|
||||||
|
|
||||||
|
chart.updateOptions({
|
||||||
|
series: data.data,
|
||||||
|
labels: data.names,
|
||||||
|
} as ApexOptions);
|
||||||
|
};
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await GetStats();
|
await GetStats();
|
||||||
await initializeChart();
|
await initializeChart();
|
||||||
|
await initializePieChart();
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user