Chart Refresh Issue

2 posts, 0 answers
  1. Razi
    Razi avatar
    1 posts
    Member since:
    May 2009

    Posted 28 May 2009 Link to this post

    Hi.

    I'm having a fairly frustrating problem with the chart control, that I can't get over.

    I'm trying to use the same chart for different reports based on what the user chooses.

    One report is using the chart by binding data to it. The other is manually populating it. The graph works in both scenarios. My problem is when I try to change the X-Axis label.

    Let's take this scenario. First, I generate a databound graph. Let's say it comes back with 4 bars on the X-Axis. It looks fine and works fine.

    Then I generate a report which uses the graph without databinding. Let's say it needs to display 8 bars. Now if I set:

    rdChart.PlotArea.XAxis.AutoScale =

    True

     


    Then the graph works fine, but the x-axis item labels are marked 1,2,3,4..., which I need to change.

    So I added a loop to change the X-Axis labels:

     

    Dim labels() As String = lbls.Split(",")

     

     

    For i = 0 To rdChart.PlotArea.XAxis.Items.Count - 1

     

    rdChart.PlotArea.XAxis(i).TextBlock.Text = labels(i)

     

    Next

     


    Now this code doesn't do anything, unless I add: 

    rdChart.PlotArea.XAxis.AutoScale =

    False

     


    before doing the loop.

    Now that's where the problem is. If I set AutoScale to false, the Chart stops populating the X-Axis items correctly. So for example, if the the databound chart had returned 4 bars on X-Axis, then it stays at 4, even though if the new series is supposed to have 8 bars.

    I have tried many different combinations of 

    rdChart.Series.Clear()

    rdChart.Series.ClearItems()

    rdChart.PlotArea.XAxis.ClearDataBoundState()
    rdChart.Update()

     

    rdChart.UpdateGraphics()

    rdChart.Refresh()

    and then setting the AutoScale to true, and then setting it back to false, but nothing seems to clear up the X-Axis display correctly. The number of X-Axis items displayed is not refreshing if I trun AutoScale off, and I can't set the X-Axis item labels if it's on. HELP!

  2. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 01 Jun 2009 Link to this post

    Hi Razi,

    I would suggest to keep the AutoScale to true and use the BeforeLayout event to change the labels' text. Let me know if that works for your case.

    All the best,
    Evtim
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top