I am using NReco to build PivotTables and I wanted to display a chart that corresponds to the data shown in the table. I'm trying to accomplish this with c3 charts(really like the look), but another kind of chart is welcomed.
I'm sending the NReco Pivot Table's JSON through ajax and following the examples on http://c3js.org/samples/data_rowed.html, and building my JSON in the following code:
var pivotTable = new PivotTable(lines, columns, pivotData);
var htmlResult = new StringWriter();
var jsonResult = new StringWriter();
var pvtHtmlWr = new PivotTableHtmlWriter(htmlResult);
var chartJsonWr = new PivotTableJsonWriter(jsonResult);
pvtHtmlWr.Write(pivotTable);
chartJsonWr.Write(pivotTable);
return new {Pvt = htmlResult.ToString(), Chart = jsonResult.ToString()};
Resulting in the following JSON
"Chart":"{\"Columns\":[\"Year\"],\"Rows\":[\"Spot\"],\"ColumnKeys\":[[2004],[2005]],\"RowKeys\":[[\"A\"],[\"B\"],[\"C\"]],\"Values\":[[1483.0,1396.0],[1237.0,1700.0],[18276.0,17643.0]],\"GrandTotal\":41735.0,\"ColumnTotals\":[20996.0,20739.0],\"RowTotals\":[2879.0,2937.0,35919.0],\"MeasureLabels\":[\"Sum"],\"PivotDataVersion\":\"TRIAL http://www.nrecosite.com/pivot_data_library_net.aspx\"}"
In my ajax call I parse the Json and try to build the chart
success: function (response) {
$("#pvtTable").html(response.Pvt);
var crt = JSON.parse(response.Chart);
var rows = crt.RowKeys;
var vals = crt.Values;
var chart = c3.generate({
bindto:"#pvtChart",
data: {
rows: [rows, vals]
}
});
But the chart only displays the row's labels
I tried rebuilding the arrays but with no success. So my questions are: What am I doing wrong? Can I accomplish this with NReco Json and c3 or other charts?