2014-04-23 12 views
2

得到錯誤圖表區軸 - 圖表區包含不兼容的圖表類型

Chart Area Axes - The chart area contains incompatible chart types. For example, bar charts and column charts cannot exist in the same chart area. 

 Chart Chart1 = FirstChart(dt1); 
     Chart Chart2 = CreateChart(dt2); 
     Chart1.SaveImage(stream, ChartImageFormat.Png); 
     Chart2.SaveImage(stream1, ChartImageFormat.Png); 
protected Chart FirstChart(DataTable dtRpt) 
     { 
      Chart chart = new Chart(); 
      chart.Height = 800; 
      chart.Width = 600; 
      chart.ChartAreas.Add("ChartArea1"); 

      DataTable dt = new DataTable(); 
      if (ViewState["flag"].ToString() == "true") 
      { 
       chart = ChartCode(chart, dtRpt, "10"); 
      } 
      else 
      { 
       dt = GameLib.Reports.SubjectToFill(KidId, Dt1, Dt2, Gradeid); 
       if (dt.Rows.Count <= 0) 
       { 
        chart.ChartAreas["ChartArea1"].BackImage = "~/img/noreport1.png"; 
        chart.ChartAreas["ChartArea1"].BackImageWrapMode = ChartImageWrapMode.Unscaled; 
        chart.ChartAreas["ChartArea1"].BackImageAlignment = ChartImageAlignmentStyle.Center; 
       } 
       else 
       { 
        chart = ChartCode(chart, dtRpt, "10"); 
       } 
      } 


      return chart; 
     } 

     protected Chart createchart (DataTable dtRpt) 
     { 
      Chart chart = new Chart(); 
      chart.Height = 800; 
      chart.Width = 600; 
      chart.ChartAreas.Add("ChartArea1"); 
      chart.Series.Add("Class Average "); 
      chart.Series.Add("Score "); 
      DataTable dt = new DataTable(); 
      if (ViewState["flag"].ToString() == "true") 
      { 
       chart = ChartCode(chart, dtRpt, "10"); 
      } 
      else 
      { 
       dt = GameLib.Reports.SubjectToFill(KidId, Dt1, Dt2, Gradeid); 
       if (dt.Rows.Count <= 0) 
       { 
        chart.ChartAreas["ChartArea1"].BackImage = "~/img/noreport1.png"; 
        chart.ChartAreas["ChartArea1"].BackImageWrapMode = ChartImageWrapMode.Unscaled; 
        chart.ChartAreas["ChartArea1"].BackImageAlignment = ChartImageAlignmentStyle.Center; 
       } 
       else 
       { 
        chart = ChartCode(chart, dtRpt, "10"); 
       } 
      } 

      return chart; 
     } 
      protected Chart ChartCode(Chart chart, DataTable dtRpt, string width) 
    { 
     if (width == "15") 
     { 
      chart.Series.Add("Number of games"); 
      chart.Series.Add("Child Played Count"); 
     } 
     chart.Series.Add("Class Average "); 
     chart.Series.Add("Score "); 

     for (int i = 0; i < dtRpt.Rows.Count; i++) 
     { 

      chart.Series[0].Points.AddXY(dtRpt.Rows[i].ItemArray[0], dtRpt.Rows[i].ItemArray[4]); 
      chart.Series[1].Points.AddXY(dtRpt.Rows[i].ItemArray[0], dtRpt.Rows[i].ItemArray[5]); 
      chart.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar; 
      chart.Series[1].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar; 

      System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#3F66B1"); 
      System.Drawing.Color col1 = System.Drawing.ColorTranslator.FromHtml("#DD3B26"); 
      chart.Series[0].Color = col; 
      chart.Series[1].Color = col1; 
     } 


     chart.Legends.Add("Legend1"); 
     chart.Legends[0].Enabled = true; 
     chart.Legends[0].Alignment = System.Drawing.StringAlignment.Center; 
     chart.ChartAreas["ChartArea1"].AxisX.Title = "Topics"; 
     chart.ChartAreas["ChartArea1"].AxisY.Title = "Average Score "; 
     if (width == "15") 
     { 
      chart.ChartAreas["ChartArea1"].AxisY.LabelStyle.Format = "{#}%"; 
     } 
     chart.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false; 
     chart.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false; 
     chart.Series[0]["PixelPointWidth"] = width; 
     chart.Series[1]["PixelPointWidth"] = width; 
     ChartArea ca = chart.ChartAreas["ChartArea1"]; 
     ca.AxisX.LineWidth = 1; 
     ca.AxisY.LineWidth = 1; 
     ca.AxisX2.LineWidth = 1; 
     ca.AxisY2.LineWidth = 1; 
     ca.AxisX.LabelStyle.IsEndLabelVisible = true; 
     ca.AxisY.LabelStyle.IsEndLabelVisible = true; 
     ca.AxisX.IsMarginVisible = true; 
     ca.AxisY.IsMarginVisible = true; 
     ca.AxisX.ScaleBreakStyle.LineWidth = 1; 
     ca.AxisY.ScaleBreakStyle.LineWidth = 1; 
     ca.AxisX.Interval = 1; 
     // ca.AxisY.Interval = 10; 
     ca.AxisX.Minimum = 0; 
     ca.AxisX.Maximum = int.Parse(dtRpt.Rows.Count.ToString()) + 1; 
     ca.AxisX.Interval = 1; 
     ca.AxisY.ScaleBreakStyle.StartFromZero = StartFromZero.Yes; 
     ca.AxisX.IntervalAutoMode = IntervalAutoMode.FixedCount; ca.AxisY.IntervalAutoMode = IntervalAutoMode.FixedCount; 
     ca.AxisX.IsStartedFromZero = true; 
     ca.AxisY.IsStartedFromZero = true; 
     ca.AxisX.TextOrientation = TextOrientation.Auto; 
     ca.AxisY.TextOrientation = TextOrientation.Auto; 
     ca.AxisX.LabelAutoFitMinFontSize = 6; 
     ca.AxisY.LabelAutoFitMinFontSize = 6; 
     ca.AxisX.LabelStyle.IsEndLabelVisible = true; 
     ca.AxisY.LabelStyle.IsEndLabelVisible = true; 
     ca.AlignmentOrientation = AreaAlignmentOrientations.Horizontal; 
     ca.AxisY.LabelStyle.IsEndLabelVisible = true; 
     ca.AxisY = new Axis { LabelStyle = new LabelStyle() { Font = new System.Drawing.Font("Verdana", 7.5f) } }; 
     ca.AxisY.Minimum = 0; 

     if (width == "15") 
     { 
      ca.AxisY.Interval = 25; 
      ca.AxisY.LabelStyle.Format = "{#}%"; 
      ca.AxisY.Maximum = 100; 
     } 
     return chart; 
    } 

其實兩者都是酒吧chart.I不爲什麼這個錯誤誰能幫助我解決這個錯誤。它簡短的代碼; firstchart和createchart exicutes創建代碼,我指定了系列類型............................... .................................................. .................................

+0

張貼一些更多的代碼。例如,你的方法'FirstChart'和'CreateChart'做什麼?你在哪裏添加系列? – mmathis

回答

1

我自己找到解決方案;的 代替

chart.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar; 
chart.Series[1].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar; 

替換

foreach (Series series in chart.Series) 
{ 
     series.ChartType = SeriesChartType.Bar; 
}