How to mount a Stackedcolumn100 chart?

1

I am returning a query from the database to DataTable and serializing it to Json .

I use the following method to Serialize my DataTable to Json.

 public static string ConvertDataTabletoString(DataTable dt)
    {
        System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
        Dictionary<string, object> row;
        foreach (System.Data.DataRow dr in dt.Rows)
        {
            row = new Dictionary<string, object>();
            foreach (System.Data.DataColumn col in dt.Columns)
            {
                row.Add(col.ColumnName, dr[col]);
            }
            rows.Add(row);
        }
        return serializer.Serialize(rows);
    }

And I have the following result:

  

[{"name": "DIFS - GEMS - GAECS - Eng. Man. Eq.   Conventional "," date ":" [96] "}, {" name ":" DIFS - GEMS - GAECS - Eng.   Man "," Conventional "," data ":" [95.51] "}, {" name ":" DIFS - GEMS -   GAECS - Eng. Man. Conventional "," data ":" [89.7] "}, {" name ":" DIFS -   GEMAS - GAECS - Eng. Man. Eq.   Conventional "," date ":" [97.05] "}, {" name ":" DIFS - GEMS - GAECS - Eng.   Man "," Conventional "," data ":" [86.86] "}, {" name ":" DIFS - GEMS -   GAECS - Eng. Man. Conventional "," data ":" [90] "}, {" name ":" DIFS -   GEMAS - GAECS - Eng. Man. Conventional "," data ":" [47.35] "}]

My code is right, you can see it here at JSFIELD.

Here is complete code.

Find out that the only thing wrong would be in the data property, which instead of "data":[86.86] is "data":"[86.86]" . Is there any way to control this?

    
asked by anonymous 27.04.2015 / 21:44

1 answer

2

Follow the solution in JS.

var dados = [{"name":"DIFS - GEMAS - GAECS - Eng. Man. Eq. Convencionais","data":"[96]"},
             {"name":"DIFS - GEMAS - GAECS - Eng. Man. Eq. Convencionais","data":"[95.51]"},
             {"name":"DIFS - GEMAS - GAECS - Eng. Man. Eq. Convencionais","data":"[89.7]"},
             {"name":"DIFS - GEMAS - GAECS - Eng. Man. Eq. Convencionais","data":"[97.05]"},
             {"name":"DIFS - GEMAS - GAECS - Eng. Man. Eq. Convencionais","data":"[86.86]"},
             {"name":"DIFS - GEMAS - GAECS - Eng. Man. Eq. Convencionais","data":"[90]"},
             {"name":"DIFS - GEMAS - GAECS - Eng. Man. Eq. Convencionais","data":"[47.35]"}];

Convert JSON to a list of objects using JSON.parse as follows:

var dados = JSON.parse(dados);

Use $.map to interact on the list:

var seriesDados = $.map(dados, function(data, i){
   return {
     name: data['name'],
       //expressão regular que remove tudo diferente de 0-9 (caracteres numéricos) e ponto(.)
       data: [parseFloat(data['data'].replace(/[^0-9.]/g,""))]
   };
});

And in the series put the test variable.

    
27.04.2015 / 22:09