Click here to Skip to main content
11,714,345 members (82,202 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP Javascript JSON NET
Good morning, I would like to use the library MORRIS.JS with ASP. Net, I know I must be a JSON object, but not how to do it, someone help me? As an example if I do a query on a database and want to send the data in JSON format so the library becomes MORRIS.JS the graph, can someone give me a simple example? Thanks to this community and sorry my English is not very good, I would say that is bad enough, but I will understand!

Linkt to library[^]
Posted 4-Feb-13 7:17am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

for example you can convert a generic list to json like below
public class Person
public string Name{get;set;}
public int Age{get;set;}
List<person> person=new List<person>();
person.Add(new Person{Name="Jemi","23"});
person.Add(new Person{Name="Jemi2","23"});
//Converting person list to jSon by using JavaScriptSerializer
JavaScriptSerializer jss = new JavaScriptSerializer(person);
string output = jss.Serialize(person);

Hope this helps
Garcia AlfredoS at 4-Feb-13 13:57pm
agree, however I should spend the format is as follows:

* Play with this code and it'll update in the panel opposite.
* Why not try some of the options above?
element: 'donut-example',
data: [
{label: "Download Sales", value: 12},
{label: "In-Store Sales", value: 30},
{label: "Mail-Order Sales", value: 20}

I do not quite understand is how to format the data obtained either from an object in that format, can you give me a clearer example? aspx file including ... cs ..... and js.
Because that's so generic it's hard to understand, can you put the aspx ... cs and js for these three archvios form a whole that can see more clearly?
Thank you very much for your time!
Garcia AlfredoS at 4-Feb-13 14:10pm
I have to agree all formatted in json output, but with the example I gave above and must form the json of morris.js, ..... I can you clarify this?
Adil Battal KAYA at 6-May-14 9:55am
data: $.parseJSON(dataJson),

after serializing do parseJSON for chart data.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I also encountered the same problem with you,just did a project on morris example,I hope to help you.
        <div id="myfirstchart" style="height: 250px; "  >

The data transport by Json, It should be noted that Json' Key have quotation ,you must delete it,you can use Regular Expression . this is MVC. My English is not good.Hope you can understand.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 540
1 Maciej Los 259
2 Richard MacCutchan 230
3 OriginalGriff 140
4 F-ES Sitecore 140
0 Sergey Alexandrovich Kryukov 545
1 CHill60 375
2 Maciej Los 324
3 Richard MacCutchan 310
4 OriginalGriff 260

Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 28 May 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100