获取错误
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;
}
实际上两者都是条形图。我不知道为什么这个错误可以帮助我解决这个错误。它简短的代码; firstchart和createchart都说明了我指定系列类型的创建代码......... .................................................. .................................................. .....
答案 0 :(得分: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;
}