I'm showing a Chart to the user which has one chart area with a line chart. On this, I got, for example, one line. This line has about 200 values. Those values do all have a description (e.g. "01.01.2013"
, "05.02.2013"
and so on).
When the Chart is shown, I can only see two descriptions, even if there would be space for much more descriptions. The line gets displayed correctly, but there are only two points described.
I rotated the Text vertically so there is more space, but this didn't help. If I display less values (5 or 10), the descriptions get shown correctly.
This is how it actually looks like (the descriptions are actually Strings, not Dates).
Thank you for your help!
EDIT: My Code:
chart.ChartAreas(0).AxisY.Maximum = 6
chart.ChartAreas(0).AxisY.Minimum = 1
chart.ChartAreas(0).AxisX.LabelStyle.Angle = -90
chart.Series.Clear()
chart.ChartAreas(0).AxisY.StripLines.Clear()
Dim myStripLine1 as new StripLine()
myStripLine1.IntervalOffset = 4
chart.ChartAreas(0).AxisY.StripLines.add(myStripLine1)
'now adding all series
chart.Series.Add("Chemie") 'just to take the example in the image above
chart.Series(chart.Series.Count - 1).ChartType = DataVisualization.Charting.SeriesChartType.Line
chart.Series(chart.Series.Count - 1).BorderWidth = 4
'now adding quite much values (on every date, every Serie has a value)
chart.Series(chart.Series.Count - 1).Points.AddXY("01.03.2011", 4.9)
On every date, a new point gets entered for all series, but only those points where they have important values get highlighted. Those values between are calculated mathematically.
One example to explain this: I got two series, one has two values (6 and 4) on point "01.01.2013"
and "03.01.2013"
. The other series has 3 values (4,6,5.5) on "01.01.2013"
,"02.01.2013"
and "03.01.2013"
. When I just display them, the first series will end at the second date, even if there was a value for the third date. I solved this by filling a dummy value at the first series with date "02.01.2013"
which is just the average at this point (=5). This point simply does not get highlighted with a marker bullet. This is how I draw my graph.
EDIT2:
After Skippy's answer and comment, my new trial. The variable MainForm.grades
is a Dictionary(Of Integer,Dictionary(Of String, String))
which contains around 150 grades
Dim subjects As New Dictionary(Of Integer, ArrayList)
Dim allgrades As New ArrayList
For Each grade In MainForm.grades
Dim cD As New Dictionary(Of String, String)
cD.Add("SUBJECTID", grade.Value("SUBJECTID"))
cD.Add("GRADE", grade.Value("GRADE"))
cD.Add("DATE", grade.Value("DATE"))
allgrades.Add(cD)
Next
cht_main.ChartAreas(0).AxisX.IntervalType = DateTimeIntervalType.Days
cht_main.ChartAreas(0).AxisX.LabelStyle.Angle = -90
Dim gradesDateSorter = New gradesDateSorter()
allgrades.Sort(gradesDateSorter)
For Each grade In allgrades
If Not subjects.ContainsKey(Integer.Parse(grade("SUBJECTID"))) Then
subjects.Add(Integer.Parse(grade("SUBJECTID")), New ArrayList)
End If
Dim gradeDict As New Dictionary(Of String, String)
gradeDict.Add("DATE", grade("DATE"))
gradeDict.Add("GRADE", grade("GRADE"))
subjects(Integer.Parse(grade("SUBJECTID"))).Add(gradeDict)
Next
For Each subject In subjects
'adding serie
cht_main.Series.Add(MainForm.subjects(subject.Key)("NAME"))
cht_main.Series(cht_main.Series.Count - 1).ChartType = DataVisualization.Charting.SeriesChartType.Line
cht_main.Series(cht_main.Series.Count - 1).BorderWidth = 4
'cht_main.Series(cht_main.Series.Count - 1).IsXValueIndexed = True
For Each grade In subject.Value
cht_main.Series(cht_main.Series.Count - 1).Points.AddXY(Date.Parse(grade("DATE")), Double.Parse(grade("GRADE")))
Next
Next
On the 5th last row I commented IsXValueIndexed=True
because when I activated it, the chart gets generated with a big red error cross.
SOLUTION
Setting the Interval on the X-Axis does the trick!
chart.ChartAreas(0).AxisX.Interval = 1
Solution by Skippy
Yes I agree with Michael. I can only add to the explanation at this point.
By setting your interval:
You are guaranteeing that your X-axis values will be plotted only, at frequency of 4 " generic x-axis" values:
Setting this to vale to 1 will give a value for every x-axis value, that is incremented as a whole number (in this case days)
And to declare the x-axis values to type:
As mentioned by Michael in his comment. By setting the
Every indexed X-axis value will be plotted.
As explained in the following quote, with the link provided.
http://support2.dundas.com/onlinedocumentation/winchart2005/Data_IndexedXValues.html
I sourced my original information regarding intervals and interval offsets at the following site:
http://support2.dundas.com/Default.aspx?article=705
Here it discusses datatype and addresses your issue of highlighted values.
This is a an explanation for setting the interval.
I have added these sources:
In response to ZedGraph I advised:
And: After viewing your code
It doesn't show that you have formatted your date and date string. There also needs to be taken into account, that you are not using the en-US date format (I'm in Australia, so we have the same format as you). The default date type is for en-US.
Please refer to
DateTime.ParseExact
Methodhttp://msdn.microsoft.com/en-us/library/system.datetime.parseexact.aspx
I have taken snippets from MSDN.
See link: http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx
Please see this link: http://msdn.microsoft.com/en-us/library/system.datetime.aspx
So it should go, something like this:
ALSO:
I think you should convert the string date representation to an actual datetime object before adding it to the chart. I didn't test it but something like this: (where
yourDate
is the string you used to pass to the chart)The chart can manage datetime object instead of strings and it has special code that deals with dates. If you do this you you can adjust how it is displayed by formatting:
If you wanted to only display every other day change the interval to 2