簡體   English   中英

在燭台C#中繪制所有X軸日期值

[英]Plotting all X-axis date values in candlestick C#

需要找到一個解決方案,將所有日期值繪制在C#中的燭台圖表中。 有一個結構,其中包含日期作為字符串以及open,high,low和close的值。 使用庫存數據從.csv文件中讀取值。 目前,它正確地繪制所有點,但僅根據繪制的值的數量繪制一些日期值。 見附圖。

我想讓它顯示適用於圖表上的值的所有日期。 因此,在這種情況下,應顯示的日期如下:

  • 2015年2月25日
  • 2015年2月24日
  • 2015年2月23日
  • 2015年2月20日
  • 2015年2月19日
  • 2015年2月18日
  • 2015年2月17日
  • 2015年2月13日
  • 2015年2月12日
  • 2015年2月11日
  • 2015年2月10日
  • 2015年2月9日
  • 2015年2月6日
  • 2015年2月5日
  • 2015年2月4日
  • 2015年2月3日
  • 2015年2月2日

僅顯示2015年2月2日,2015年2月9日,2015年2月17日和2015年2月24日的日期。 以下是與圖表當前狀態相關的代碼。

chart1.Series["stock"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Candlestick;
/*set the maximum y value axis*/
chart1.ChartAreas[0].AxisY.Maximum = System.Convert.ToDouble(maxX);
/*set the minimum y value axis*/
chart1.ChartAreas[0].AxisY.Minimum = System.Convert.ToDouble(minY);
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.LightGray;
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.LightGray;
chart1.ChartAreas[0].AxisX.MinorGrid.LineColor = System.Drawing.Color.LightGray;
chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 45;

foreach (candleStick stock in chartData)
{
    int currentIndex = chart1.Series["stock"].Points.Count;
    chart1.Series["stock"].Points.AddXY(stock.date, stock.high);
    chart1.Series["stock"].Points[currentIndex].YValues[0] = System.Convert.ToDouble(stock.high);
    chart1.Series["stock"].Points[currentIndex].YValues[1] = System.Convert.ToDouble(stock.low);
    chart1.Series["stock"].Points[currentIndex].YValues[2] = System.Convert.ToDouble(stock.open);
    chart1.Series["stock"].Points[currentIndex].YValues[3] = System.Convert.ToDouble(stock.close);
    chart1.Series["stock"].Points[currentIndex].AxisLabel = stock.date;
    chart1.Series["stock"].Points[currentIndex].Color = Color.Black;
}

任何有關這方面的幫助將不勝感激。 謝謝!

這可能有所幫助,

chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.NotSet;
chart1.ChartAreas[0].AxisX.Interval=1;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM