I have a Microsoft Chart with a single Series that is defined as ChartType = SeriesChartType.Line. The X-Axis is a DateTime value, and all is working as expected except the last point on the chart. It is overlapping with the end of the chart, and does not look right. See the picture below, how the last point is falling off the chart. In fact, you can see how even the very first point is slightly overlapped by the left border of the chart.
My question is: Can anyone suggest a way to correct this? I imagine there may be a way to apply a margin or padding to the X-Axis of the ChartArea, but I can't find it if it's there.
Below is the code that creates the chart:
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);
This queries the data from the database and populates the chart:
// 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);
}
Thanks!