我有一個MsSql數據庫,它可以計算兩個日期之間的時間間隔(秒)。這工作正常。之後我在C#中使用此列,並將它們寫入數組中。在秒錶中將秒轉換爲hhh:mm:ss
此數組是稍後的圖表輸入。 到目前爲止,這工作得很好,但我無法找到一種方式來顯示像hhh:mm:ss這樣的格式的秒數,因爲時間跨度可能大於24h。
我試過ChartArea.AxisY.LabelStyle.Format =「hhmmss」;但它根本不起作用。
有沒有人有一個想法,我可以做到這一點?
編輯: 我補充這樣的數據:
chart2.Series.Clear();
chart2.ChartAreas.Clear();
Series BoxPlotSeries = new Series();
ChartArea ChartArea2 = new ChartArea();
ChartArea ChartArea3 = new ChartArea();
chart2.ChartAreas.Add(ChartArea2);
chart2.ChartAreas.Add(ChartArea3);
ChartArea2.Name = "Data Chart Area";
ChartArea3.Name = "BoxPlotArea";
BoxPlotSeries.Name = "BoxPlotSeries";
BoxPlotSeries.ChartType = SeriesChartType.BoxPlot;
BoxPlotSeries.ChartArea = "BoxPlotArea";
chart2.Series.Add(BoxPlotSeries);
Series Input1 = new Series();
Input1.Name = "Input1";
Input1.ChartType = SeriesChartType.Point;
Input1.ChartArea = "Data Chart Area";
chart2.Series.Add(Input1);
chart2.Series["Input1"].Points.DataBindY(InputArray);
chart2.ChartAreas["BoxPlotArea"].AxisX.CustomLabels.Add(2, 0.0, "BoxPlot1");
chart2.Series["BoxPlotSeries"]["BoxPlotSeries"] = "Input1";
chart2.Series["BoxPlotSeries"]["BoxPlotShowMedian"] = "true";
chart2.Series["BoxPlotSeries"]["BoxPlotShowUnusualValues"] = "false";
chart2.Series["BoxPlotSeries"]["PointWidth"] = "0.5";
chart2.Series["BoxPlotSeries"].IsValueShownAsLabel = false;
ChartArea2.Visible = false;
ChartArea3.BackColor = Color.FromArgb(224,224,224);
//I tried to format it this way but it didn't work
//ChartArea3.AxisY.LabelStyle.Format = "{0:HHHmmss}";
chart2.ChartAreas["BoxPlotArea"].AxisX.LabelStyle.Angle = -90;
EDIT2: 這裏就是我如何填充輸入數組
int[] InputArray = new int[1000000];
int c = 0;
con.Open();
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
int n;
if (int.TryParse(dr[0].ToString(),out n) == true)
{
InputArray[c] = Convert.ToInt32(dr[0].ToString());
c++;
}
}
}
if (c == 0) { c = 1; }
Array.Resize(ref InputArray, c - 1);
在Excel格式顯示時大於24被稱爲 「並[h]:MM:SS; @」
EDIT4:
由於@TAW我幾乎設法解決我問題。我做了一些調整他的解決方案以及與此想出了:
在圖表代碼塊:
值「MAX」之前設定。
ChartArea3.AxisY.MajorTickMark.Interval = addCustomLabels(ChartArea3, BoxPlotSeries, 60 * 60, max);
int addCustomLabels(ChartArea ca, Series series, int interval, int max)
{
int tickNo = 0;
ca.AxisY.CustomLabels.Clear();
if(max/interval > 10)
{
interval = (max/10) - (max/10) % (60*30);
tickNo = (max/10) - (max/10) % (60*30);
}
if (max/interval <= 2)
{
interval = (max/4) - (max/4) % (60 * 15);
tickNo = (max/4) - (max/4) % (60 * 15);
}
for (int i = 0; i < max; i += interval)
{
CustomLabel cl = new CustomLabel();
cl.FromPosition = i - interval/2;
cl.ToPosition = i + interval/2;
cl.Text = hhh_mm_ss(i);
ca.AxisY.CustomLabels.Add(cl);
}
return tickNo;
}
我的問題是現在,即使當代碼通過它運行沒有任何問題有時被示出沒有軸拉布勒(除了0:00)。
有沒有人和想法有什麼可能是錯的?
你使用什麼樣的圖表? –
Boxplot圖表 – FriendlyGuy
什麼是UI框架?什麼是您使用的類型的全名? –