I made a scatter chart with VS C# 2022 using SpreadsheetLight library.
First column is DateTime, it doesn't show as Time in chart, any hint will be appreciated very much, as I have been for days with this problem.
Here's my code:
private void Scatter_Click(object sender, EventArgs e) { int C;
SLDocument sl = new SLDocument();
SLStyle s_Time = sl.CreateStyle();
s_Time.SetVerticalAlignment(VerticalAlignmentValues.Center);
s_Time.SetHorizontalAlignment(HorizontalAlignmentValues.Center);
s_Time.FormatCode = "HH:MM:SS";
SLTextImportOptions csv = new SLTextImportOptions();
csv.UseCommaDelimiter = true;
sl.ImportText("C:\\test.csv", "A1", csv);
for (C = 2; C < 10; C++)
{
sl.SetCellStyle(C,1,s_Time);
}
SLChart chart;
chart = sl.CreateChart("A1", "C9");
chart.SetChartType(SLScatterChartType.ScatterWithSmoothLinesAndMarkers);
chart.SetChartStyle(SLChartStyle.Style2);
chart.PrimaryValueAxis.FormatCode = "HH:MM:SS";
chart.SetChartPosition(2,5,22,16);
sl.InsertChart(chart);
sl.SaveAs("C:\\Scatter.xlsx");
Close();
}
Here is my csv file content:
"Hours","Col 1","Col 2"
05:06:07,35.6,25.3
06:07:08,38.2,28.4
07:08:09,41.6,26.9
08:09:10,39.8,28.1
09:10:11,43.4,26.7
10:11:12,40.2,29.6
11:12:13,38.9,26.1
12:13:14,38.7,27.6