1

我希望有人可以帮助我理解这个图表行为。基于下面的 XML

<ChartData>
 <ChartData Count="157">
  <Year>2012</Year> 
  <MonthString>April</MonthString> 
  <Month>4</Month> 
  </ChartData>
 <ChartData Count="196">
  <Year>2012</Year> 
  <MonthString>May</MonthString> 
  <Month>5</Month> 
  </ChartData>
 <ChartData Count="181">
  <Year>2012</Year> 
  <MonthString>June</MonthString> 
  <Month>6</Month> 
  </ChartData>
 <ChartData Count="222">
  <Year>2012</Year> 
  <MonthString>July</MonthString> 
  <Month>7</Month> 
  </ChartData>
 <ChartData Count="261">
  <Year>2012</Year> 
  <MonthString>August</MonthString> 
  <Month>8</Month> 
  </ChartData>
 <ChartData Count="163">
  <Year>2012</Year> 
  <MonthString>September</MonthString> 
  <Month>9</Month> 
  </ChartData>
 <ChartData Count="161">
  <Year>2012</Year> 
  <MonthString>October</MonthString> 
  <Month>10</Month> 
  </ChartData>
 <ChartData Count="181">
  <Year>2012</Year> 
  <MonthString>November</MonthString> 
  <Month>11</Month> 
  </ChartData>
 <ChartData Count="184">
  <Year>2012</Year> 
  <MonthString>December</MonthString> 
  <Month>12</Month> 
  </ChartData>
 <ChartData Count="227">
  <Year>2013</Year> 
  <MonthString>January</MonthString> 
  <Month>1</Month> 
  </ChartData>
 <ChartData Count="194">
  <Year>2013</Year> 
  <MonthString>February</MonthString> 
  <Month>2</Month> 
  </ChartData>
 <ChartData Count="177">
  <Year>2013</Year> 
  <MonthString>March</MonthString> 
  <Month>3</Month> 
  </ChartData>
 <ChartData Count="74">
  <Year>2013</Year> 
  <MonthString>April</MonthString> 
  <Month>4</Month> 
  </ChartData>
  </ChartData>

到这个 C# 图表代码

 chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;
                    chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Interval = 1;

                    chart1.Series["Series1"].IsVisibleInLegend = false;
                   chart1.Series["Series1"].Font = new
                   System.Drawing.Font("Arial", 10.0F, System.Drawing.FontStyle.Italic);

                    chart1.Series[0].IsValueShownAsLabel = true;
                    chart1.Series["Series1"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
                    chart1.DataBindCrossTable(chartgrouped, "Year", "MonthString", "Count", "");

当我查看图表时,我看到了两个不同的问题。

  1. 该图表并未显示所有月份。
  2. 该图表不正确地表示数据,它显示了 2003 年的数据

这是我用来查询数据并获取 XML 的查询

   var chartgrouped = (from x in data  group x by new { x.DateOpened.Month, x.DateOpened.Year } into g
            select new ChartData
                                {
                                    Year = g.Key.Year,
                                    Month = g.Key.Month,
                                    MonthString = string.Format("{0}",
                                    CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(g.Key.Month)),
                                    Count = g.Count()
                               }) .ToList();

这是我得到的屏幕截图 在此处输入图像描述

4

0 回答 0