c# - passing json values to highcharts from .net code behind -
var javascriptxvalue= $.parsejson($("#hdnxaxis").val()); var javascriptyvalue= $.parsejson($("#hdnyaxis").val()); $(document).ready(drawmygraph1); function drawmygraph1() { chart = new highcharts.chart( { chart: { type: 'column', renderto: 'container3', defaultseriestype: 'area' }, title: { text: '' }, subtitle: { text: '' }, xaxis: { categories: javascriptxvalue, labels: { enabled: false } }, yaxis: { title: { text: 'no of patients' } }, credits: { enabled: false }, tooltip: { formatter: function () { return this.series.name + ' - ' + highcharts.numberformat(this.y, 0); } }, series: javascriptyvalue }); }
c# code void fastmovingstocksbarchart(string date1, string date2, string selperiod, string sql) { dataset dschart = new dataset(); dschart = _obj_mis.doctorpatientreportchart(date1, date2, selperiod,sql); list lstxaxis = new list(); list lstcolors = new list();
lstcolors.add("#3366dd"); //lstcolors.add("#ffee22"); //lstcolors.add("#33bbcc"); lstcolors.add("#cc0022"); //lstcolors.add("#ff0000"); lstcolors.add("#339900"); lstcolors.add("#ff7700"); lstcolors.add("#33bbcc"); lstcolors.add("#99eeee"); lstcolors.add("#6699ff"); lstcolors.add("#9966bb"); lstcolors.add("#99bb66"); lstcolors.add("#ff7700"); lstcolors.add("#ffee22"); lstcolors.add("#ffcbb9"); lstcolors.add("eaec93"); lstcolors.add("d7fbe6"); lstcolors.add("ffcaca"); (int = 0; < dschart.tables[0].rows.count; i++) { lstxaxis.add(dschart.tables[0].rows[i]["doctor name"].tostring()); } list<chartex> lstseries = new list<chartex>(); int count = 0; (int = 0; < dschart.tables[0].rows.count; i++) { chartex oex = new chartex(); oex.name = dschart.tables[0].rows[i]["doctor name"].tostring(); //oex.data.add(convert.toint32(dschart.tables[0].rows[i]["patients"])); oex.data = new list<int>() { convert.toint32(dschart.tables[0].rows[i]["patients"]) }; oex.color = lstcolors[count]; lstseries.add(oex); count++; if (count >= lstcolors.count) count = 0; } //convert x axis data json javascriptserializer oserializer1 = new javascriptserializer(); hdnxaxis.value = oserializer1.serialize(lstxaxis); //convert y axis data json javascriptserializer oserializer2 = new javascriptserializer(); hdnyaxis.value = oserializer1.serialize(lstseries);
}
i not getting values "javascriptxvalue" , "javascriptyvalue" inside chart function
can me
regards prabhu
presumably, 'hdnxaxis' id of hiddenfieldcontrol server control? perhaps id not think
var javascriptxvalue= $.parsejson($("#"+ <%= hdnxaxis.clientid %>).val());
instead of passing strings via input, use server tags directly inject values page. this:
<%= "alert('" + mypublicproperty + "')" %>
this should alert value of property defined in code behind. set js variable so:
<%= "var javascriptxvalue = '" + xproperty + "';" %>
you need run bit of code directly in aspx/ascx/razor page set variables though, think it's better relying on control particular id though.
Comments
Post a Comment