最近做个小网站,在统计一些数据报表时决定使用OWC11的方案,在做单数据的柱形图,饼图时都没有问题,但是在做多数据的多曲线图,发现描出的数据不对,系统自动把写进去的数据叠加了。现在把多曲线走势图代码贴出来,大家帮忙看看是什么问题?谢谢了 public string createPicture(string fileName, ChartChartTypeEnum type, string title, bool hasAxes, string strCategory, string[] strValue, string[] seriesName,string Xname, string Yname, int width, int height)
{ //图表工作区
Microsoft.Office.Interop.Owc11.ChartSpace thisChartSpace = new Microsoft.Office.Interop.Owc11.ChartSpace();
//增加一个图表
Microsoft.Office.Interop.Owc11.ChChart thisChChart = thisChartSpace.Charts.Add(0);
//增加一个图表上的系列数组
//Microsoft.Office.Interop.Owc11.ChSeries thisChSeries = thisChChart.SeriesCollection.Add(i);
//Microsoft.Office.Interop.Owc11.ChSeries[] thisChSeries = new ChSeries[10]; //显示图例
thisChChart.HasLegend = true; //设置标题
thisChChart.HasTitle = true;
thisChChart.Title.Caption = title; //图表类型
thisChChart.Type = type;
if (hasAxes)
{ //给定x,y轴图示说明
thisChChart.Axes[0].HasTitle = true;
thisChChart.Axes[0].Title.Caption = Xname; thisChChart.Axes[1].HasTitle = true;
thisChChart.Axes[1].Title.Caption = Yname;
}
string[] LineColor = { "blue", "red", "yellow", "Black", "DarkOrange", "DeepPink", "Gold", "Green", "Pink", "GreenYellow" }; //根据线条数目添加系列数
for(int i = 0;i<seriesName.Length;i++)
{
thisChChart.SeriesCollection.Add(i);
thisChChart.SeriesCollection[i].Line.Color = LineColor[i];
thisChChart.SeriesCollection[i].Caption = seriesName[i];
thisChChart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimSeriesNames, ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), seriesName[i]);
//thisChChart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimXValues,ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),XValue[i]);
//thisChChart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimYValues,ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),YValue[i]);
thisChChart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimValues, Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), strValue[i]);
thisChChart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimCategories, Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), strCategory);
} //倒出图像文件
try
{
thisChartSpace.ExportPicture(HttpContext.Current.Server.MapPath(fileName), "gif", width, height);
//return HttpContext.Current.Server.MapPath(fileName);
return fileName;
//HttpContext.Current.Response.Write("<img src='" + HttpContext.Current.Server.MapPath(fileName) + "'/>"); }
catch (Exception ex)
{
//抛出异常信息
HttpContext.Current.Response.Write(ex);
return null;
}
}
{ //图表工作区
Microsoft.Office.Interop.Owc11.ChartSpace thisChartSpace = new Microsoft.Office.Interop.Owc11.ChartSpace();
//增加一个图表
Microsoft.Office.Interop.Owc11.ChChart thisChChart = thisChartSpace.Charts.Add(0);
//增加一个图表上的系列数组
//Microsoft.Office.Interop.Owc11.ChSeries thisChSeries = thisChChart.SeriesCollection.Add(i);
//Microsoft.Office.Interop.Owc11.ChSeries[] thisChSeries = new ChSeries[10]; //显示图例
thisChChart.HasLegend = true; //设置标题
thisChChart.HasTitle = true;
thisChChart.Title.Caption = title; //图表类型
thisChChart.Type = type;
if (hasAxes)
{ //给定x,y轴图示说明
thisChChart.Axes[0].HasTitle = true;
thisChChart.Axes[0].Title.Caption = Xname; thisChChart.Axes[1].HasTitle = true;
thisChChart.Axes[1].Title.Caption = Yname;
}
string[] LineColor = { "blue", "red", "yellow", "Black", "DarkOrange", "DeepPink", "Gold", "Green", "Pink", "GreenYellow" }; //根据线条数目添加系列数
for(int i = 0;i<seriesName.Length;i++)
{
thisChChart.SeriesCollection.Add(i);
thisChChart.SeriesCollection[i].Line.Color = LineColor[i];
thisChChart.SeriesCollection[i].Caption = seriesName[i];
thisChChart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimSeriesNames, ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), seriesName[i]);
//thisChChart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimXValues,ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),XValue[i]);
//thisChChart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimYValues,ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),YValue[i]);
thisChChart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimValues, Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), strValue[i]);
thisChChart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimCategories, Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), strCategory);
} //倒出图像文件
try
{
thisChartSpace.ExportPicture(HttpContext.Current.Server.MapPath(fileName), "gif", width, height);
//return HttpContext.Current.Server.MapPath(fileName);
return fileName;
//HttpContext.Current.Response.Write("<img src='" + HttpContext.Current.Server.MapPath(fileName) + "'/>"); }
catch (Exception ex)
{
//抛出异常信息
HttpContext.Current.Response.Write(ex);
return null;
}
}
確認一下是否是樓上所說的數據重疊了調用如下:
protected void Button1_Click(object sender, EventArgs e)
{
string filename = createPicture(@"haha.gif"
, ChartChartTypeEnum.chChartTypeBar3D
, "haha", false, "haha1"
, new string[] { "1", "2", "3" }
, new string[] { "5", "6", "7" }
, "haha2"
, "haha3"
, 1000
, 1000);
}
后来改成了没有Stacked类型后OK了。
不过还是要感谢各位