locked
Column chart with Date X axis RRS feed

  • Discussion générale

  • I have a problem to generate a chart displaying a column chart whose X axis is Date.
    The axis has minor ticks and grid every day.
    My values are for each day, so I would like that each column has a width of exactly one day.

    Here is how I configure the chart :

    area = this.chart1.ChartAreas["area"];
    
    area.AxisX.LabelAutoFitMinFontSize = 7;
    area.AxisX.LabelAutoFitMaxFontSize = 7;
    area.AxisX.IntervalType = DateTimeIntervalType.Days;
    area.AxisX.Interval = 1;
    
    area.AxisX.MajorGrid.Enabled = false;
    
    area.AxisX.MajorTickMark.IntervalType = DateTimeIntervalType.Weeks;
    area.AxisX.MajorTickMark.Interval = 1;
    area.AxisX.MajorTickMark.IntervalOffsetType = DateTimeIntervalType.Days;
    area.AxisX.MajorTickMark.IntervalOffset = (int)System.Globalization.DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek;
    area.AxisX.MajorTickMark.Size = 4f;
    area.AxisX.MajorTickMark.Enabled = true;
    
    area.AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Weeks;
    area.AxisX.LabelStyle.Interval = 1;
    area.AxisX.LabelStyle.IntervalOffsetType = DateTimeIntervalType.Days;
    area.AxisX.LabelStyle.IntervalOffset = (int)System.Globalization.DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek;
    
    area.AxisX.MinorGrid.IntervalType = DateTimeIntervalType.Days;
    area.AxisX.MinorGrid.Interval = 1;
    area.AxisX.MinorGrid.Enabled = true;
    
    area.AxisX.MinorTickMark.IntervalType = DateTimeIntervalType.Days;
    area.AxisX.MinorTickMark.Interval = 1;
    area.AxisX.MinorTickMark.Size = 2f;
    area.AxisX.MinorTickMark.Enabled = true;
    
    area.AxisX.Minimum = DateTime.Today.AddDays(1 - 28).ToOADate();
    area.AxisX.Maximum = DateTime.Today.AddDays(1).ToOADate();
    area.AxisX.LabelStyle.Format = "d/M";
    
    area.AxisY.IsStartedFromZero = true;
    area.AxisY.LabelAutoFitMinFontSize = 7;
    area.AxisY.LabelAutoFitMaxFontSize = 7;
    


    Then I add one point, and it seems good :

    chartSeries.Points.AddXY(new DateTime(2011, 9, 19), 65);
    


    But when I have two points, the size of columns become curious and incorrect.

    chartSeries.Points.AddXY(new DateTime(2011, 9, 23), 99);
    chartSeries.Points.AddXY(new DateTime(2011, 9, 19), 65);
    


    The width of columns is too large : each column takes place of 4 days instead of 1 day.

    I tried many options, but I can't reolve that...

     


    • Modifié Flod69 lundi 10 octobre 2011 19:51
    • Type modifié Ciprian Duduiala jeudi 13 octobre 2011 05:27 pas en français
    • Déplacé Ciprian Duduiala jeudi 13 octobre 2011 05:28 pas en français (Origine :Développement .NET (en général))
    lundi 10 octobre 2011 19:50

Toutes les réponses