I have to make a graph based on a list of items.
For this I use dataview chart and ASP. Net.
The problem is that my graph is empty but I have data.
The data:
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <Expense>
<Type>Achat pièce</Type>
<Total>173.50</Total>
</Expense>
</Root>
The code use to build the char:
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");
There must be something wrong with the way you are parsing your XML. You seem to be using some custom FromJson method and some XmlDocument to fill your dataset but I guess that your dataset doesn’t contain any values because the following works perfectly fine:
result: