c# - jqPlot not working with dates -
i'm new using json, , i'm trying generate jqplot dates on x-axis , numbers on y-axis. this, i'm passing data json string view. however, jqplot not being generated.
here code in view:
<script type="text/javascript"> $(document).ready(function () { var plot = $.jqplot('placeholder', @viewbag.chart, { title: 'visual report', axes: { xaxis: { renderer: $.jqplot.dateaxisrenderer } } }); }); </script> i'm using newtonsoft.json.jsontextwriter create json string; can have this?
private string json(dictionary<string, dictionary<string, list<point>>> points, string radio) { var sb = new stringbuilder(); var sw = new stringwriter(); using (var jsonwriter = new jsontextwriter(sw)) { jsonwriter.writestartarray(); foreach (var merchant in points) { foreach (var type in merchant.value) { jsonwriter.writestartarray(); foreach (var point in type.value) { jsonwriter.writestartarray(); jsonwriter.writevalue(point.date.value.tostring("yyyy-mm-dd")); if (radio == "amount") { jsonwriter.writevalue(point.sumamount); } else { jsonwriter.writevalue(point.countamount); } jsonwriter.writeendarray(); } jsonwriter.writeendarray(); } } jsonwriter.writeendarray(); } string result = sw.tostring(); return result; } when replace line
jsonwriter.writevalue(point.date.value.tostring("yyyy-mm-dd")); with
jsonwriter.writevalue(point.sumamount); the chart magically appears (after comment out axes options). seems problem stems parsing of dates in json string, still doesn't work after tried using jquery.parsejson() , json.parse(). doing wrong here?
update: although wasn't able resolve issue, managed achieve wanted (more or less) through ajax (which proved have own learning curve, that's story day).
Comments
Post a Comment