?
Solved

Microsoft Chart vb.net - How to add labels to the x-axis

Posted on 2011-02-21
6
Medium Priority
?
4,694 Views
Last Modified: 2012-05-11
I'm using the code below to create a chart. The chart is created fine and it gives me 31 tickmarks on the x-axis, but there are no labels. I'd like the labels to be on the tickmarks on the x-axis. The labels will be numbered according to the number of tickmarks, in this case 1 through 31. I've tried to find examples for custom labels but can't get anything to work. How can I generate these labels? Thanks!
dHRInterval = xValues.Count / RideDetail.RideDetailDistance.Text
            Chart1.Series.Add("HR")
            Chart1.Series("HR").ChartType = SeriesChartType.Line

            'Bind chart to ArrayList
            Chart1.Series("HR").Points.DataBindXY(xValues, yValues)
            Chart1.ChartAreas("ChartArea1").AxisX.Interval = dHRInterval
            Chart1.ChartAreas("ChartArea1").AxisX.IntervalOffset = 0

Open in new window

0
Comment
Question by:myester
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:kdwood
ID: 34945778

myester,

I have a couple of chart projects I can take a look for you.   Off the top of my head, did you try setting the Axis label styel format as follows:

Chart1.ChartAreas("ChartArea1").AxisX.LabelStyle.Format = "####.####"  (or whatever number format you need)

Regards,

Keith


0
 

Author Comment

by:myester
ID: 34946199
Keith thanks for the reply. I tried that and I still don't have any labels on the x-axis. I'm trying some different things with custom labels but can't get anything to work yet.
0
 
LVL 10

Expert Comment

by:kdwood
ID: 34946580
myester,

I have a feeling it has to do with your dHRInterval.   I created a simple chart project, set the AxisX interval to 1 and the tick labels show up fine.  However, as I played with the interval and set it to values that exceeded my datapoints, I was able to get the label to disappear.

Here is my sample code:


Dim xValues As String() = {"Red", "Blue", "Green"}
        Dim yValues As Double() = {14, 8, 11}
        
        Chart1.Series.Add("HR")
        Chart1.Series("HR").ChartType = SeriesChartType.Line

        'Bind chart to ArrayList
        Chart1.Series("HR").Points.DataBindXY(xValues, yValues)
        Chart1.ChartAreas("ChartArea1").AxisX.Interval = 1
        Chart1.ChartAreas("ChartArea1").AxisX.IntervalOffset = 0

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:myester
ID: 34947532
Keith, in this case the dHRInterval is a little over 42 and there are 1318 datapoints. The dHRInterval is going to vary from say 25 to 75 or a 100. The datapoints will vary too and will always exceed the values generated by the interval. In this chart the datapoints represent a heart rate value and the x-axis will be the mileage ridden on a bike ride. The calculation that generates dHRInterval gives me one tickmark for each mile so I need to keep that. I think I may be on to something with custom labels. If you can think of anything else please let me know. In the meantime when I get some more time to work on this I'll see if I can get the custom labels working and let you know how it goes. Thanks!
0
 

Accepted Solution

by:
myester earned 0 total points
ID: 34948000
Keith,

I have the custom labels working with the code below. I appreciate your response.

Dim dHRIntervalConstant As Double = dHRInterval
            Dim i As Integer = 1
            For index As Double = 0 To RideDetail.RideDetailDistance.Text
                Chart1.ChartAreas(0).AxisX.CustomLabels.Add(New CustomLabel(dHRInterval - 10, dHRInterval + 10, i.ToString, 1, LabelMarkStyle.None))
                dHRInterval = dHRInterval + dHRIntervalConstant
                i = i + 1
            Next
0
 

Author Closing Comment

by:myester
ID: 34986603
I found the solution on my own.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question