We help IT Professionals succeed at work.
Get Started

JQPlot reading from webservice

2,821 Views
Last Modified: 2012-05-11
Hi,

I have been trying to get a jqplot chart (a pie chart, in this instance) to work using a C# webservice as the data.  I have tried returning data in all sorts of formats, but it is always being interpreted by JQuery as an object, and I cannot get it to transform into anything useful.  The below works perfectly when I either hard code the data value, or pull it from a text file (for example [[['first', 8], ['second', 26], ['third', 12]]];), but obviously this isn't all that useful.  

Here's the jquery:

  $.ajax({
        type: "POST",
        url: "WEBSERVICEURL",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            plot1 = $.jqplot('pie1', JSON.parse(response.toString(), {
                gridPadding: { top: 0, bottom: 38, left: 0, right: 0 },
                seriesDefaults: { renderer: $.jqplot.PieRenderer, trendline: { show: false }, rendererOptions: { padding: 8, showDataLabels: true} },
                legend: { show: true, placement: 'outside', rendererOptions: { numberRows: 1 }, location: 's', marginTop: '15px' }
            });
        },
        failure: function (errMsg) {
            $('#errorMessage').text(errMsg);  //errorMessage is id of the div
        }
    });

I have tried the following return types in the webservice:
String, List<CustomObject>, Array, JSON String (formatted as per normal JSON response)

When I do an alert(response) in the JQuery above, I get <object>, and the errMsg just says "object XMLHTTPRequest".

I am new to jplot, and am slowly going mad trying to get this to work, so any advice would be gratefully received.
Comment
Watch Question
Systems Engineer
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE