Files
NKC/NKC_WF/WebUserControls/cmp_DailyStatsPlot.ascx
T
Samuele Locatelli ef0afc508e Bozza grafici Daily
2021-10-05 18:18:16 +02:00

89 lines
2.9 KiB
Plaintext

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="cmp_DailyStatsPlot.ascx.cs" Inherits="NKC_WF.WebUserControls.cmp_DailyStatsPlot" %>
<%--https://www.chartjs.org/--%>
<div class="row">
<div class="col-12 px-2">
<h4>Batch Stats Plot</h4>
</div>
<div class="col-12 px-2">
<asp:HiddenField runat="server" ID="hfPlaceCod" Value="*" />
<asp:HiddenField runat="server" ID="hfPlotType" Value="" />
<asp:HiddenField runat="server" ID="hfDateStart" Value="" />
<asp:HiddenField runat="server" ID="hfDateEnd" Value="" />
<asp:HiddenField runat="server" ID="hfLegend" Value="" />
<canvas id="myChartTS" height="200"></canvas>
</div>
</div>
<script type="text/javascript">
// funzione eseguita se successo al caricamento
function OnSuccess_(reponse) {
// recupero dati restituiti
var dataTS = reponse;
//console.log('Received data', dataTS);
// preparo etichette
var labelsTS = dataTS.map(function (item) {
return item['x'];
});
//console.log('labels data', labels);
var myOptions = {
responsive: true,
maintainAspectRatio: false,
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
},
}],
},
animation: {
duration: 250
},
};
// recupero obj chart
var ctx = document.getElementById('myChartTS').getContext('2d');
var chart = new Chart(ctx, {
type: 'line',
data: {
labels: labelsTS,
datasets: [{
label: '<%=hfLegend.Value %>',
borderColor: 'rgb(7, 173, 236)',
lineTension: 0,
//steppedLine: false,
data: dataTS
}]
},
options: myOptions
});
}
// errore in reload!
function OnErrorCall_(repo) {
alert("Errore recupero dati grafico!");
}
// effettuo plotting grafico TimeSerie!
function plotTS() {
console.log("api/DayStats/<%=hfPlaceCod.Value %>?StartDate=<%=hfDateStart.Value %>&EndDate=<%=hfDateEnd.Value %>&PlotType=<%=hfPlotType.Value%>");
// caricamento pagina
$.ajax({
type: "GET",
url: "../api/DayStats/<%=hfPlaceCod.Value %>?StartDate=<%=hfDateStart.Value %>&EndDate=<%=hfDateEnd.Value %>&PlotType=<%=hfPlotType.Value%>",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess_,
error: OnErrorCall_
});
}
// funzione di drawing ad OGNI pageload!
function pageLoad() {
// chiamo recupero dati + plot della TS
plotTS();
//console.log('pageLoad!');
}
</script>