需要找到一种解决方案来在 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 日
仅显示 2/2/2015、2/9/2015、2/17/2015 和 2/24/2015 的日期。以下是与图表当前状态相关的代码。
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;
}
对此的任何帮助将不胜感激。谢谢!