SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Custom JSON string from form data

    Hi,
    I've been struggling with this concept for several days now and thought i'd give this a shot for some advice.

    I'm using FusionCharts to plot some data based on a series of radio and checkbox selections. I want to re-render my chart each time a radio button changes. I know how to do that part. I'm getting stumped with building my JSON string to use in the chart.

    Fusioncharts expects a variable containing a JSON object. It's expecting a certain format though (key, value pairs). I know there are jQuery plugins that will get the values from a form and create a JSON object but like i said, there are arrays in this data and i dont think that parseJSON or JSONify does what i need.

    I'm hoping to get some advice on how i might approach this.

    thanks,
    John

  2. #2
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe jQuery's serializeArray could be what you're looking for...
    You will have to make your own array or object that contains the necessary data to send to FusionCharts and then serialize it.
    FOR SALE: 1 set of morals, never used, will sell cheap

  3. #3
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    I've tried jQuery SerializeArray. The big problem is that I'm just not very good as a programmer I need the data from my form to come out looking like my chart needs. below is an excerpt from my working static chart data. There are are things in here that just aren't in my form at all like "dataset, and "data," or "value." The "seriesname:..." is arbitrary and could be anything. The first "value" : "0" is going to be same for every data point. always starting with 0. So really what i need to come out of my form (on change) is the second value. I'm guessing i've got to find some way to insert these static values as i iterate through my form elements in the js but not really sure how.

    -john

    Format FusionCharts expects:
    ...
    "dataset":[
    {
    "seriesname":"Set full retirment age to",
    "data":[
    {
    "value":"0"
    },
    {
    "value":"100"
    }
    ]
    },
    {
    "seriesname":"Set payroll tax cap to",
    "data":[
    {
    "value":"0"
    },
    {
    "value":"130"
    }
    ]
    },


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •