I am a rookie with Fusion charts and XML. I am trying to use the VS2008 built in XML generator but fusion charts keeps saying invalid xml data. If I save the data to a file first the chart works just fine.
public string GetMonthlyPassDownChartHtml(){
string tmpY = "";
switch (ddYear.SelectedValue)
{
case "2007":
tmpY = "07";
break;
case "2008":
tmpY = "08";
break;
case "2009":
tmpY = "09";
break;
case "2010":
tmpY = "10";
break;
default:
break;
}
var passDownRaw = from p in db.PassDownLinqs select p;
XElement xml = new XElement("chart", new XAttribute("caption", "PassDown Metrics"),
new XAttribute("xAxisName", "Month"),
new XAttribute("yAxisName", "Number of Entries"),
new XElement("Set", new XAttribute("label", "'Jan'"),
new XAttribute("value", passDownRaw.Where(c => c.Date >= Convert.ToDateTime("1/1/" + tmpY) && c.Date <= Convert.ToDateTime("1/" + DateTime.DaysInMonth(Convert.ToInt32(tmpY), 1) + "/" + tmpY)).Select(c => c.ID).Count())),
new XElement("Set", new XAttribute("label", "'Feb'"),
new XAttribute("value", passDownRaw.Where(c => c.Date >= Convert.ToDateTime("2/1/" + tmpY) && c.Date <= Convert.ToDateTime("2/" + DateTime.DaysInMonth(Convert.ToInt32(tmpY), 2) + "/" + tmpY)).Select(c => c.ID).Count())),
new XElement("Set", new XAttribute("label", "'Mar'"),
new XAttribute("value", passDownRaw.Where(c => c.Date >= Convert.ToDateTime("3/1/" + tmpY) && c.Date <= Convert.ToDateTime("3/" + DateTime.DaysInMonth(Convert.ToInt32(tmpY), 3) + "/" + tmpY)).Select(c => c.ID).Count())),
new XElement("Set", new XAttribute("label", "'Apr'"),
new XAttribute("value", passDownRaw.Where(c => c.Date >= Convert.ToDateTime("4/1/" + tmpY) && c.Date <= Convert.ToDateTime("4/" + DateTime.DaysInMonth(Convert.ToInt32(tmpY), 4) + "/" + tmpY)).Select(c => c.ID).Count())),
new XElement("Set", new XAttribute("label", "'May'"),
new XAttribute("value", passDownRaw.Where(c => c.Date >= Convert.ToDateTime("5/1/" + tmpY) && c.Date <= Convert.ToDateTime("5/" + DateTime.DaysInMonth(Convert.ToInt32(tmpY), 5) + "/" + tmpY)).Select(c => c.ID).Count())),
new XElement("Set", new XAttribute("label", "'Jun'"),
new XAttribute("value", passDownRaw.Where(c => c.Date >= Convert.ToDateTime("6/1/" + tmpY) && c.Date <= Convert.ToDateTime("6/" + DateTime.DaysInMonth(Convert.ToInt32(tmpY), 6) + "/" + tmpY)).Select(c => c.ID).Count())),
new XElement("Set", new XAttribute("label", "'Jul'"),
new XAttribute("value", passDownRaw.Where(c => c.Date >= Convert.ToDateTime("7/1/" + tmpY) && c.Date <= Convert.ToDateTime("7/" + DateTime.DaysInMonth(Convert.ToInt32(tmpY), 7) + "/" + tmpY)).Select(c => c.ID).Count())),
new XElement("Set", new XAttribute("label", "'Aug'"),
new XAttribute("value", passDownRaw.Where(c => c.Date >= Convert.ToDateTime("8/1/" + tmpY) && c.Date <= Convert.ToDateTime("8/" + DateTime.DaysInMonth(Convert.ToInt32(tmpY), 8) + "/" + tmpY)).Select(c => c.ID).Count())),
new XElement("Set", new XAttribute("label", "'Sep'"),
new XAttribute("value", passDownRaw.Where(c => c.Date >= Convert.ToDateTime("9/1/" + tmpY) && c.Date <= Convert.ToDateTime("9/" + DateTime.DaysInMonth(Convert.ToInt32(tmpY), 9) + "/" + tmpY)).Select(c => c.ID).Count())),
new XElement("Set", new XAttribute("label", "'Oct'"),
new XAttribute("value", passDownRaw.Where(c => c.Date >= Convert.ToDateTime("10/1/" + tmpY) && c.Date <= Convert.ToDateTime("10/" + DateTime.DaysInMonth(Convert.ToInt32(tmpY), 10) + "/" + tmpY)).Select(c => c.ID).Count())),
new XElement("Set", new XAttribute("label", "'Nov'"),
new XAttribute("value", passDownRaw.Where(c => c.Date >= Convert.ToDateTime("11/1/" + tmpY) && c.Date <= Convert.ToDateTime("11/" + DateTime.DaysInMonth(Convert.ToInt32(tmpY), 11) + "/" + tmpY)).Select(c => c.ID).Count())),
new XElement("Set", new XAttribute("label", "Dec0" + tmpY),
new XAttribute("value", passDownRaw.Where(c => c.Date >= Convert.ToDateTime("12/1/" + tmpY) && c.Date <= Convert.ToDateTime("12/" + DateTime.DaysInMonth(Convert.ToInt32(tmpY), 12) + "/" + tmpY)).Select(c => c.ID).Count()))
);
//xml.Save("C:Documents and SettingsMy DocumentsVisual Studio 2008ProjectsPassDown MetricsPassDown MetricsDataData1.xml");
return FusionCharts.RenderChartHTML("../FusionCharts/Column3D.swf", "", xml.ToString(), "myFirst", "800", "600", false);}
}
The xml looks like this before it is saved to the file.
<chart caption="PassDown Metrics" xAxisName="Month" yAxisName="Number of Entries">
<Set label="'Jan'" value="0" />
<Set label="'Feb'" value="0" />
<Set label="'Mar'" value="0" />
<Set label="'Apr'" value="0" />
<Set label="'May'" value="0" />
<Set label="'Jun'" value="0" />
<Set label="'Jul'" value="20" />
<Set label="'Aug'" value="79" />
<Set label="'Sep'" value="115" />
<Set label="'Oct'" value="94" />
<Set label="'Nov'" value="412" />
<Set label="Dec007" value="1266" />
</chart>
When its saved to the file it works just fine and this is what it looks like.
<?xml version="1.0" encoding="utf-8"?>
<chart caption="PassDown Metrics" xAxisName="Month" yAxisName="Number of Entries">
<Set label="'Jan'" value="0" />
<Set label="'Feb'" value="0" />
<Set label="'Mar'" value="0" />
<Set label="'Apr'" value="0" />
<Set label="'May'" value="0" />
<Set label="'Jun'" value="0" />
<Set label="'Jul'" value="20" />
<Set label="'Aug'" value="79" />
<Set label="'Sep'" value="115" />
<Set label="'Oct'" value="94" />
<Set label="'Nov'" value="412" />
<Set label="Dec007" value="1266" />
</chart>
Does the missing "<?xml version="1.0" encoding="utf-8"?>" from the data in memory cause the issue?