Chart axis automatically adding dates

Hello

I'm generating a line chart in vb.net.  The series I'm adding is for dates (excluding weekends ) in a month. However the chart seems to be automatically including the weekends so  I am getting axis points for this month at 01/09/13, 08/09/13, 15/09/13 etc.  although these dates are not in the datarows that I am using to create the series.

Can anyone explain this?

Thanks
LVL 1
Petermcg001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
The intelligence behind the chart uses linear axes by default when possible. So numbers and dates missing from the data points are still shown because normally you'd want that consistency in the way the data is presented. I'm not sure if there's an easy way to disable that mechanism in general but a little trick you can use is to convert the x value to a string, then the numeric interpretation is not done and the values shown on the x axis are only the ones you provide, nothing else.

Just a little example:
Imports System.Windows.Forms.DataVisualization.Charting

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim r As New Random()
        With Chart1
            With .Series(.Series.Count - 1)
                .ChartType = SeriesChartType.Line
                .BorderWidth = 3
                .MarkerStyle = MarkerStyle.Diamond
                .MarkerSize = 7
                .MarkerColor = Color.Red
                For i As Integer = -2 To 2
                    Dim d As Date = DateTime.Now.Date.AddDays(i * 7 - (DateTime.Now.DayOfWeek - 1))
                    For j = 0 To 4
                        .Points.AddXY(d.ToShortDateString, r.NextDouble() * 10)
                        d = d.AddDays(1)
                    Next
                Next
            End With
            With .ChartAreas(0)
                .AxisX.Interval = 1
                .AxisY.Interval = 1
            End With
        End With
    End Sub

End Class

Open in new window

chart
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Petermcg001Author Commented:
Hello,

Firstly, please accept my apologies for delaying.  I posted the question just as I was going on leave.

Your solution worked perfectly! As you say passing the value as a string rather than the raw data value disabled the automatic inclusion of missing dates.

Thanks so much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.