将行和列添加到Google DataTable Net Wrapper

时间:2018-09-25 10:04:11

标签: c# charts google-visualization google-chartwrapper google-datatable

我正在从头开始创建Google DataTable Net Wrapper DataTable。但是我不知道如何向数据表添加行。我已经完成了下面的代码

Google.DataTable.Net.Wrapper.DataTable GDt = new Google.DataTable.Net.Wrapper.DataTable();
for (int i = 0; i < dtReports.Columns.Count; i++)
{
    Google.DataTable.Net.Wrapper.Column gc = new Google.DataTable.Net.Wrapper.Column();
    gc.Id = dtReports.Columns[i].Caption.Substring(0, dtReports.Columns[i].Caption.IndexOf("~"));
    gc.Label = dtReports.Columns[i].Caption.Substring(dtReports.Columns[i].Caption.IndexOf("~"), dtReports.Columns[i].Caption.Length);
    GDt.AddColumn(gc);

    for (int j = 0; j < dtReports.Rows.Count; j++)
    {
        Google.DataTable.Net.Wrapper.Row gr = GDt.NewRow();

        // Code to add datatable current column and row value to Google Row
    }
}

无法找到将值添加到行和特定列的代码。帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

这是一种适合现有代码的方法:

for (int j = 0; j < dtReports.Rows.Count; j++)
{
    // Code to add datatable current column and row value to Google Row
    Google.DataTable.Net.Wrapper.Row gr = i == 0 ? GDt.NewRow() : GDt.Rows.ElementAt(j);
    gr.AddCell(new Cell(dtReports.Rows[j][i]));
    if (i == 0) GDt.AddRow(gr);
}