在烛台C#中绘制所有X轴日期值

时间:2015-02-26 17:05:33

标签: c# mschart candlestick-chart

需要找到一个解决方案,将所有日期值绘制到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;
}

对此的任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:0)

这可能有所帮助,

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