المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : excel x-axis in Time format 00:00:00 using C#



C# Programming
05-21-2009, 05:10 PM
hi, i am doing a program to plot time vs speed in excel file. but right now i have some problems into doing so. i am unable to convert the x-axis into time format.. below is the code i have written.... please help by giving examples... thanks lots!!

while (((Microsoft.Office.Interop.Excel.Range)oldsheet.Cells[row, column]).Value2 != null)
{
string splitcell = ((Microsoft.Office.Interop.Excel.Range)oldsheet.Cells[row, column]).Value2.ToString();

split = splitcell.Split(',');

int.TryParse(split[0], out hour);
int.TryParse(split[1], out min);
int.TryParse(split[2], out sec);
int.TryParse(split[21], out rpm);

time = new DateTime(1, 1, 1, hour, min, sec);

newsheet1.Cells[row, column] = time.ToString("HH:mm:ss");
newsheet1.Cells[row, column + 1] = rpm;

row++;
}
row--;

range = newsheet1.get_Range("A2", "B" + row.ToString());
xlChart.Legend.Clear();

Microsoft.Office.Interop.Excel.Axis x = (Microsoft.Office.Interop.Excel.Axis)xlChart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCatego ry, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary);
x.CategoryType = Microsoft.Office.Interop.Excel.XlCategoryType.xlTimeScale;
x.BaseUnit = Microsoft.Office.Interop.Excel.XlTimeUnit.xlDays;
//x.MajorUnitScale = Microsoft.Office.Interop.Excel.XlTimeUnit.xlDays;
//x.MajorUnit = 0.0208333333;
x.HasTitle = true;
x.AxisTitle.Text = "Time";

Microsoft.Office.Interop.Excel.Axis y = (Microsoft.Office.Interop.Excel.Axis)xlChart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlValue, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary);
y.HasTitle = true;
y.AxisTitle.Text = "Speed";

xlChart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlXYScatterSmoothNoMarkers;
xlChart.SetSourceData(range, Type.Missing);

series = (Microsoft.Office.Interop.Excel.Series)xlChart.SeriesCollection(1);
series.Format.Line.Weight = (float)0.25;