我需要帮助编程绘图多个百分点,比可容纳在一个Excel系列。
根据http://office.microsoft.com/en-us/excel/HP100738491033.aspx 2007年Excel图表上显示的点的最大数量256000假定每个系列在32000点帽出,8系列都必须绘制完整的256000点。 我的客户要求每个图表位的最大数量的绘制,由于与我们合作的大型数据集。
我有一个C#适度经验/ Excel的互操作,所以我认为这将是很容易通过每个组的32000点编程方式创建一个工作表,然后循环,并将其添加到图作为一个系列,停止当数据被完全绘制或8系列绘制。 如果有色正常,8系列是从一个单一的一系列可视没有区别。
不幸的是我在这里。 我遇到的主要问题是:
(全尺寸) 可以在一个数据序列使用的2-d图表数据点的最大数量是32000 ... http://img14.imageshack.us/img14/9630/errormessagen.png
这弹出,奇怪的是,似乎当我执行这一行:
并伴随有:
从HRESULT异常:0x800AC472 http://img21.imageshack.us/img21/5153/exceptionb.png
我不明白我怎么之前我甚至指定要绘制的数据可以产生这样的弹出/警告/异常。 是Excel的巧言令色这里?
作为暂时的解决办法,我已经把chart.ChartType =图图表类型语句转换成一个try-catch块,所以我可以继续下去。
如下面所示,我的“分块”代码工作为目的,而是试图将数据添加到图表时,我仍然遇到了同样的问题。 Excel中说,我想,当清楚我不是为了绘制太多了点。
( 全尺寸图像 ) 与监视窗口代码块http://img12.imageshack.us/img12/5360/snippet.png
我知道我可能没有正确地与每个系列相关联但X值,但我试图得到这个工作之前,我走的更远。
任何帮助将不胜感激。
下面是完整的代码:
public void DrawScatterGraph(string xColumnLetter, string yColumnLetterStart, string yColumnLetterStop, string xAxisLabel, string yAxisLabel, string chartTitle, Microsoft.Office.Interop.Excel.XlChartType chartType, bool includeTrendline, bool includeLegend)
{
int totalRows = dataSheet.UsedRange.Rows.Count; //dataSheet is a private class variable that
//is already properly set to the worksheet
//we want to graph from
if (totalRows < 2) throw new Exception("Not generating graph for " + chartTitle.Replace('\n', ' ')
+ " because not enough data was present");
ChartObjects charts = (ChartObjects)dataSheet.ChartObjects(Type.Missing);
ChartObject chartObj = charts.Add(100, 300, 500, 300);
Chart chart = chartObj.Chart;
try { chart.ChartType = chartType; }
catch { } //i don't know why this is throwing an exception, but i'm
//going to bulldoze through this problem temporarily
if (totalRows < SizeOfSeries) //we can graph the data in a single series - yay!
{
Range xValues = dataSheet.get_Range(xColumnLetter + "2", xColumnLetter + totalRows.ToString());
Range yValues = dataSheet.get_Range(yColumnLetterStart + "1", yColumnLetterStop + totalRows.ToString());
chart.SetSourceData(yValues, XlRowCol.xlColumns);
SeriesCollection seriesCollection = (SeriesCollection)chart.SeriesCollection(Type.Missing);
foreach (Series s in seriesCollection)
{
s.XValues = xValues;
}
}
else // we need to split the data across multiple series -- this doesn't work yet
{
int startRow = 1;
while (startRow < totalRows)
{
int stopRow = (startRow + SizeOfSeries)-1;
if (stopRow > totalRows) stopRow = totalRows;
Range curRange = dataSheet.get_Range(yColumnLetterStart + startRow.ToString(), yColumnLetterStop + stopRow.ToString());
try
{
((SeriesCollection)chart.SeriesCollection(Type.Missing)).Add(curRange, XlRowCol.xlColumns,
Type.Missing, Type.Missing, Type.Missing);
}
catch (Exception exc)
{
throw new Exception(yColumnLetterStart + startRow.ToString() + "!" + yColumnLetterStop + stopRow.ToString() + "!" + exc.Message);
}
startRow = stopRow+1;
}
}
chart.HasLegend = includeLegend;
chart.HasTitle = true;
chart.ChartTitle.Text = chartTitle;
Axis axis;
axis = (Axis)chart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary);
axis.HasTitle = true;
axis.AxisTitle.Text = xAxisLabel;
axis.HasMajorGridlines = false;
axis.HasMinorGridlines = false;
axis = (Axis)chart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary);
axis.HasTitle = true;
axis.AxisTitle.Text = yAxisLabel;
axis.HasMajorGridlines = true;
axis.HasMinorGridlines = false;
if (includeTrendline)
{
Trendlines t = (Trendlines)((Series)chart.SeriesCollection(1)).Trendlines(Type.Missing);
t.Add(XlTrendlineType.xlLinear, Type.Missing, Type.Missing, 0, 0, Type.Missing, false, false, "AutoTrendlineByChameleon");
}
chart.Location(XlChartLocation.xlLocationAsNewSheet, "Graph");
}