Sunday 15 February 2015

Flot Chart Conversion C# Javascript/AJAX - Bar Chart -


I am trying to convert a C # list object to the right format for the float bar chart. For some reason I can not seem to work it correctly I have tried many different ways I am going back JSON is valid JSON and the list is valid but for some reason float chart data is a Any help someone wants in a different format will be appreciated. Thanks!

JSON Array

  here [{"color": "red", "data": ["agriculture", 0, 2]}, {"color": "Red", "data": ["healthcare", 0,1]}, {"color": "red", "data": ["manufacturing", 0,0]}, "color": "red" , "Data": ["retail", 0,0]}, {"color": "red", "data": ["information technology", 0,0]}]  
< P> I use this method to do this:

  $ .ajax ({type: "POST", url: "Summary. Command / GuestBartTerms data", data: JSON. Stringify ({userid: userid}), contentType: "application / json; charset = utf-8", data type: "json", success: function (response) {barSummaryData = response.d; Var jsonArray = JSON.parse (response.d); // This format / var data = [[data: [[0, 1]], color: "red"}, {data: [1, 2]] to work "Plaque" = $. ($ ('(# BarSummaryPla) Ceholder'), jsonArray, {$ ('$ 2'), {Data: [2, 3]], color: "green" Series: {time: {show: true, barwidth: 0.3, align: "center"}}, xaxis: {ticks: ticks}, grid: {hoverable: true, clickable: true}});}, failure: function (Msg) {$ ('# Ms placeholder'). Text (msg); }});  

There is a C # method in ASMX:

  public string getSummaryBarChartSeriesData (int userid) {list & lt; Series & gt; Chain data = new list & lt; Series & gt; (); Datatable dt = new datatable (); Dt.Clear (); Dt = chartcode.RetrieveSummaryBarChartData (userid); Int countOfRows = 0; Foreign exchange (the databar line in dt.rows) {List & lt; Object & gt; ObjData = new list & lt; Object & gt; (); ObjData.Add (.line ["name"] ToString ()); ObjData.Add (countOfRows); ObjData.Add (Convert.ToInt32 (line ["CountOfStudents"])); Chaindata.ed (new carriercluster series {data = objetta, color = "red"}); } Var jsonSerialiser = new JavaScriptSerializer (); Var json = jsonSerialiser.Serialize (SeriesData); Return json; }  

For some reason the C # Jason String is in valid format for JSON, but is not the right format for the Flot chart, which is the chart system that I am trying to use.

First, by the documentation, there should be an array of arrays of data field numbers, example:
  {label: "y = 3 On the contrary, you have a flat array of numbers with a string in: [, 0, 3], [10, 3]]      {"data": ["agriculture", 0,2], "color": "red",} . What is the purpose of the string - is this series label? 

Next, did you forget to increase countOfRows ? This is always zero in your code.

Assume that you want to increase the count and want to set the line [name "]" as the chain label, the following will be followed by ASP compliant JSON should be created:

  public class series {public string color {get; Set; } Public listing & lt; IList & lt; Double & gt; & Gt; Data {Received; Set; } Public string label {get; Set; }}  

and then:

  public string getSummaryBarChartSeriesData (int userid) {var series data = new list & lt; Series & gt; (); Datatable DT = Chart Code Retrieve GoodbarData (User ID); Int countOfRows = 0; Foreign exchange (DatRao line in dt.rows) {var rawData = New list & lt; IList & lt; Double & gt; & Gt; (); RawData.Add (new double [] {countOfRows ++, convert toInt32 (line ["calculationoffestudent"])}); //objData.Add(row["Name "] ToString ()). ChainData.ed (New Career Cluster Seriejay {Data = Raw Data, Color = "Red", Label = Line ["Name"]. ToString (), // Guessing that you wanted it.}); } Var jsonSerialiser = new JavaScriptSerializer (); Var json = jsonSerialiser.Serialize (SeriesData); Return json; }  

No comments:

Post a Comment