How to map json output from [WebMethod] to d3.js bar charts

后端 未结 1 1817
小蘑菇
小蘑菇 2021-01-27 12:53

Hi I am new to d3.js.I have this following [WebMethod] in .aspx file:

    [WebMethod]  
    public static List GetProductsLINQ(         


        
相关标签:
1条回答
  • 2021-01-27 13:34

    Unlike d3.csv and d3.tsv, d3.json does not accept an accessor function (or row function).

    According to the API, these are the arguments of a d3.csv:

    d3.csv(url, row, callback);

    Compare with the argument of a d3.json:

    d3.json(url[, callback])

    I'm pasting your function and commenting out everything that is an accessor (row) function:

    d3.json("WebForm1.aspx/GetProductsLINQ", //function (json) {
        //d=json
        //d.Product_Code = +d.Product_Code;
        //return d;
    //}, 
        function (error, data) {
            if (error) throw error;
    

    So, it should be only:

    d3.json("WebForm1.aspx/GetProductsLINQ", function (error, data) {
            if (error) throw error;
    

    And then, right after it, put your accessor (row) function inside d3.json as a forEach:

    data.forEach(function(d){
        d.Product_Code = +d.Product_Code;
    });
    
    0 讨论(0)
提交回复
热议问题