我必须根据项目列表制作图表。为此,我使用 dataview 图表和 ASP。网。
问题是我的图表是空的,但我有数据。
数据:
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <Expense>
<Type>Achat pièce</Type>
<Total>173.50</Total>
</Expense>
</Root>
用于构建字符的代码:
DataSet dataSet = new DataSet();
DataTable dataTable = new DataTable("Table");
dataTable.Columns.Add("Total", typeof(string));
dataTable.Columns.Add("Type", typeof(string));
dataSet.Tables.Add(dataTable);
//GetData & fill dataTable
var listOfExpense = Helper.JsonHelper.FromJson<ExpensePie>(resp.Content);
foreach (var expense in listOfExpense.ListOfExpense)
{
dataTable.Rows.Add(expense.Total, expense.Type);
}
//Fill data view with dataset
var dataView = new DataView(dataSet.Tables["Table"]);
//Build the chart
var myChart = new Chart(width: 600, height: 400, theme: ChartTheme.Blue)
.AddSeries("Default", chartType: "bar",
xValue:dataView, xField:"Type",
yValues: dataView, yFields: "Total")
.GetBytes("png");
return File(myChart, "image/png");