dcsimg
Results 1 to 3 of 3
  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Resolved [RESOLVED] Chart X Axis Labels [VS 2010]

    Hi,

    I'm seeing a strange problem with the labels on the X axis of my charts.

    I've setup two chart areas and aligned them (which displays fine) and the user can manipulate the chart by selecting different date resolutions (Year, Month, Day, Week, Hour) and different time periods.

    The issue I'm seeing is that if a user selects say Months as the date resolution the X axis label display is inconsistent.

    If a fairly broad range for the dates is selected the X axis displays absolutely fine but as the date range narrows the X axis starts to duplicate labels ( please see the attached images).

    The second Image had a date range of 1st of May to 1st of August and as you can see the labels are duplicted.

    This is my first go with the chart control so I could be missing something basic.

    The code for the chart creation is as follows:

    Code:
        '****************** Chart Creation **************************
    
        Private Sub CreateChart()
    
            'declare local chart variables
            Dim myChartArea As ChartArea
    
            Dim loc As New System.Drawing.Point
            Dim eventSeries As New Series
            Dim timeSereies As New Series
    
            'check if the chart already exists
            If Me.pnlOverviewChart.Controls.Contains(myChart) Then
                myChart.Dispose()
            End If
    
            'Create DataView
            EventsDataView = New DataView(EventsCreated.Tables(0))
          
    
            'create new chart and the Event chart area instance
            myChartArea = New ChartArea
            myChartArea.Name = "EventChartArea"
            myChart = New Chart
    
            'Add the area
            myChart.ChartAreas.Add(myChartArea)
    
            'create a new instance of the chart area for the response time graphs
            myChartArea = New ChartArea
            myChartArea.Name = "TimeChartArea"
    
            'Add the  response time area
            myChart.ChartAreas.Add(myChartArea)
    
            'setup the rest of the chart start by adding the series for the events
            myChart.Series.Add("eventSeries").ChartArea = "EventChartArea"
            myChart.Series("eventSeries").Points.DataBindXY(EventsDataView, StrSelectedXaxis, EventsDataView, "Event Total")
    
    
    
            'add the response time series
    
            myChart.Series.Add("timeSeries").ChartArea = "TimeChartArea"
            myChart.Series("timeSeries").Points.DataBindXY(EventsDataView, StrSelectedXaxis, EventsDataView, "Average Response")
            myChart.ChartAreas("TimeChartArea").AxisX.LabelStyle.Format = strAxisX
    
            'Align the charts
           
            myChart.ChartAreas("EventChartArea").AlignWithChartArea = "TimeChartArea"
            myChart.ChartAreas("EventChartArea").AlignmentStyle = AreaAlignmentStyles.PlotPosition
    
          
            myChart.ChartAreas("EventChartArea").AxisX.LabelStyle.Enabled = False
            myChart.ChartAreas("EventChartArea").AxisY.LabelStyle.IsEndLabelVisible = False
            myChart.ChartAreas("TimeChartArea").AxisY.LabelStyle.IsEndLabelVisible = False
    
    
            'sort the X data and apply the grouping
            myChart.Series("eventSeries").Sort(PointSortOrder.Ascending, "X")
            myChart.DataManipulator.Group("SUM", 1, intDataInterval, "eventSeries")
    
    
            myChart.Series("timeSeries").Sort(PointSortOrder.Ascending, "X")
            myChart.DataManipulator.Group("AVE", 1, intDataInterval, "timeSeries")
    
    
            'Set the chart apperance elements
            myChart.Series("timeSeries").Color = Color.Orange
            myChart.Series("timeSeries").BackSecondaryColor = Color.Gold
            myChart.Series("timeSeries").BackGradientStyle = GradientStyle.VerticalCenter
            myChart.ChartAreas("TimeChartArea").BackColor = Color.SlateGray
    
            myChart.Series("eventSeries").Color = Color.Blue
            myChart.Series("eventSeries").BackSecondaryColor = Color.LightBlue
            myChart.Series("eventSeries").BackGradientStyle = GradientStyle.VerticalCenter
            myChart.ChartAreas("EventChartArea").BackColor = Color.LightGray
    
            myChart.Series("eventSeries").ChartType = eventSeriesChartType
            myChart.Series("timeSeries").ChartType = timeSeriesChartType
    
            myChart.AlignDataPointsByAxisLabel()
    
    
            'Add chart to control and set dock to fill
    
            Me.pnlOverviewChart.Controls.Add(myChart)
            myChart.Dock = DockStyle.Fill
    
    
        End Sub
    Attached Images Attached Images   
    If my post helps , please feel free to rate it

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: Chart X Axis Labels [VS 2010]

    Sorted it out, for future reference I needed to use the following.

    Code:
     myChart.ChartAreas("TimeChartArea").AxisX.Interval = 1
            myChart.ChartAreas("TimeChartArea").AxisX.IntervalType = intDataInterval + 1
    If my post helps , please feel free to rate it

  3. #3
    Hyperactive Member
    Join Date
    Sep 2014
    Posts
    404

    Re: [RESOLVED] Chart X Axis Labels [VS 2010]

    Can I ask how do you get your dates to display in the correct order, mine show in alphabetical order which puts February before Jan can you or someone please help?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width