简体   繁体   中英

JSon with HighCharts and ASP.NET

I'm new using highcharts and JSON.

My javascript code is this:

$(document).ready(function() {

    var options = {
        chart: {
            renderTo: 'grafica',
            type: 'spline'
        },
        series: [{}]
    };

    $.getJSON('ajax/gettipomov.aspx', function(data) {
        options.series[0].data = data;
        var chart = new Highcharts.Chart(options);
    });
});

And the data returned by the server and received by JavaScript is this:

[{"tipoMov":"Ajuste negativo","valorTipoMov":5},{"tipoMov":"Ajuste     positivo","valorTipoMov":5},{"tipoMov":"Compra","valorTipoMov":5},    {"tipoMov":"Transferencia","valorTipoMov":5},{"tipoMov":"Venta","valorTipoMov":5}]

The problem is that chart is not showing any data, the chart is blank: image The JSON Encoding that I use is:

var encoder = new JavaScriptSerializer();
    return encoder.Serialize(obj);

That's the format expected:

{ "name": "Ajuste negativo", "y": 5 },
{ "name": "Ajuste positivo", "y": 5 },
{ "name": "Compra", "y": 5},
{ "name": "Transferencia", "y": 5},
{ "name": "Venta", "y": 5}

tipoMov and valorTipoMov mean nothing to Highcharts , so change your Object to return the properties named accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM