Microsoft Chart Control X-Axis

时间:2014-06-10 15:50:20

标签: microsoft-chart-controls

我有一个Microsoft图表,其中包含一个定义为ChartType = SeriesChartType.Line的系列。 X轴是一个DateTime值,除了图表上的最后一个点外,所有值都按预期工作。它与图表的末尾重叠,看起来不正确。请参见下图,最后一点如何从图表中脱落。实际上,您可以看到第一个点甚至与图表的左边界略有重叠。

Picture of how the last point is falling off the chart

我的问题是:有人可以建议一种纠正方法吗?我想可能有一种方法可以在ChartArea的X轴上应用边距或填充,但如果它存在,我找不到它。

以下是创建图表的代码:

Chart chart = new Chart
{
    Width = w,
    Height = h
};

Series series = new Series("Prices");
series.ChartType = SeriesChartType.Line;
series.Palette = ChartColorPalette.None;
series.Color = ColorTranslator.FromHtml("#009ad9");
series.BorderWidth = 3;            
series.MarkerStyle = MarkerStyle.Circle;
series.MarkerSize = 7;
series.MarkerColor = Color.Salmon;
series.ShadowOffset = 2;
series.XValueType = ChartValueType.Date;
series.YValueType = ChartValueType.Double;
series.Font = new System.Drawing.Font("Trebuchet MS", 8);
chart.Series.Add(series);

ChartArea area = new ChartArea("Area1");
area.BorderColor = ColorTranslator.FromHtml("#e7e8e6");
area.BorderDashStyle = ChartDashStyle.Solid;
area.ShadowOffset = 10;
area.ShadowColor = Color.LightSlateGray;
area.BackColor = Color.White;
area.BackSecondaryColor = ColorTranslator.FromHtml("#f1f1f1");
area.BackGradientStyle = GradientStyle.TopBottom;
area.Area3DStyle.Rotation = 10;
area.Area3DStyle.Perspective = 10;
area.Area3DStyle.Inclination = 15;
area.Area3DStyle.WallWidth = 0;
area.Area3DStyle.IsClustered = false;
area.AxisY.LineColor = Color.Transparent;
area.AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#e7e8e6");
area.AxisX.LineWidth = 1;
area.AxisX.LineColor = ColorTranslator.FromHtml("#666666");
area.AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#e7e8e6");
area.AxisX.IsMarginVisible = true;
chart.ChartAreas.Add(area);

这将查询数据库中的数据并填充图表:

// Get data for id and add chart area, series, points, etc. to chart
IPriceRepository r = new PriceRepository(Properties.Settings.Default.DcrDb);
var data = r.GetChartData(id);
foreach (var plot in data)
{
    series.Points.AddXY(plot.AuctionEndDate, (double)plot.AuctionHighBid);
}

谢谢!

0 个答案:

没有答案