0
I am building the category (Xaxis) and the data series in Highcharts through Javascriptserializer. The structure works perfectly when using in Page_load, but when postback (click on Asp button inside updatepanel), it loses the value (tested through an Alert('testeValorQueFicouZerado')).
How do I make the value persist/be loaded to the chart? Below codebehind
public string xAxis { get; set; }
public string series1 { get; set; }
public string series2 { get; set; }
(DataTable tabela criada com campo Credenciado, VRE e Valor)
List<string> credL = new List<string>();
List<double> vreL = new List<double>();
string vreTemp = string.Empty;
List<double> valorL = new List<double>();
string valorTemp = string.Empty;
foreach (DataRow dr in tabela.Rows)
{
credL.Add(Convert.ToString(dr["Credenciado"]));
vreTemp = Convert.ToString(dr["VRE"]).Replace(".", string.Empty).Replace("R$ ", string.Empty);
if (vreTemp == string.Empty)
{
vreL.Add(0);
}
else
{
vreL.Add(Convert.ToDouble(vreTemp));
}
valorTemp = Convert.ToString(dr["Recuperado"]).Replace(".", string.Empty).Replace("R$ ", string.Empty);
if(valorTemp == string.Empty)
{
valorL.Add(0);
}
else
{
valorL.Add(Convert.ToDouble(valorTemp));
}
}
JavaScriptSerializer jsSerializexAxis = new JavaScriptSerializer();
xAxis = jsSerializexAxis.Serialize(credL);
JavaScriptSerializer jsSerializeseries1 = new JavaScriptSerializer();
series1 = jsSerializeseries1.Serialize(vreL);
JavaScriptSerializer jsSerializeseries2 = new JavaScriptSerializer();
series2 = jsSerializeseries2.Serialize(valorL);
And in html/js:
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_endRequest(function (sender, e) {
if (sender._postBackSettings.panelsToUpdate != null) {
chart = new Highcharts.Chart({
chart: {
renderTo: 'graficoRecuperado',
type: 'column'
},
title: {
text: 'Valor Recuperado'
},
xAxis: {
categories: eval('<%=xAxis%>')
},
yAxis: {
title: {
text: 'em reais (R$)'
}
},
series: [{
name: 'VRE',
data: eval('<%=series1%>')
}, {
name: 'Recuperado',
data: eval('<%=series2%>')
}]
});
}
});
};
</script>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<div id="graficoRecuperado" style="width:100%;height:400px;"></div>
(gridview e outros controles...)
</ContentTemplate>
</asp:UpdatePanel>