I can't seem to figure out how to set the minimum scale of a excel chart using C#.
The xaxis for the chart is loaded with values from columns "A", which are hr:min values {"08:32","08:33",...}.
I want my axis labels to start at "09:00", and I figured that setting the minimumscale is the only way of doing this.
Xaxis.MinimumScale seems to want a double value, but I want to tell it to start at 09:00. My attempt is below, but it fails when trying to set the string to the double value.
Thanks
Excel.Workbook oWB = (Excel.Workbook)oWS.Parent;
Excel.Series oSeries;
int length = numRows + 2;
string colname;
Excel.ChartObjects xlCharts;
Excel.ChartObject myChart;
Excel.Chart chartPage;
Excel.SeriesCollection oSeriesCollection;开发者_StackOverflow社区
...
xlCharts = (Excel.ChartObjects)oWS.ChartObjects(Type.Missing);
myChart = (Excel.ChartObject)xlCharts.Add(10, 80, 300, 250);
chartPage = myChart.Chart;
oSeriesCollection = (Excel.SeriesCollection)chartPage.SeriesCollection();
oSeries = oSeriesCollection.NewSeries();
oSeries.Name = "Actual";
oSeries.XValues = oWS.Range["A2:A" + length];
oSeries.Values = oWS.Range["A2","A"+length];
//Set the interval to 1 hour
Excel.Axis Xaxis;
//format the x-axis
Xaxis = (Excel.Axis)chartPage.Axes(Excel.XlAxisType.xlCategory,
Excel.XlAxisGroup.xlPrimary);
Xaxis.TickLabelSpacing = 60;
Xaxis.TickLabels.Offset = 130;
Xaxis.HasTitle = true;
Xaxis.AxisTitle.Text = "Time of day";
Xaxis.TickMarkSpacing = 60;
Xaxis.MinorTickMark = Excel.XlTickMark.xlTickMarkNone;
Excel.Range rg =(Excel.Range)oWS.Cells[28,1];
object d = rg.Value2;
Xaxis.MinimumScale = d;
It may work if you convert the time (9:00) to a fraction (9/24). Excel 2003 used to accept axis scale parameters in time and date format, but 2007 only accepts this format in limited cases.
精彩评论