dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] Chart is cutting the top of bars, but only sometimes

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2018
    Posts
    244

    Resolved [RESOLVED] Chart is cutting the top of bars, but only sometimes

    I have a chart that supposed to show bars, and it does, but sometimes it cuts the top of the bars. I have stepped into the code and can confirm that correct Y-values are there but for some reason the chart won’t auto scale, if that is what it should do.

    Here is an image of the case:

    Name:  2019-04-17_12-41-22.jpg
Views: 123
Size:  12.5 KB

    It should be like this:

    Name:  2019-04-17_12-42-15.jpg
Views: 123
Size:  12.8 KB

    My code
    Code:
    Sub Chart_Normal_Deviation(ThisListBox As ListBox, SeriesName As String)
    
            Dim TempTable As DataTable = Nothing
            Dim ItemCount As Integer = 0
            Dim MyQuery As String = ""
            Dim MyChartType As SeriesChartType = SeriesChartType.Column
            Chart_DVCategory.Series.Clear()
    
            Chart_DVCategory.Series.Add(SeriesName)
            Chart_DVCategory.Series(SeriesName).IsValueShownAsLabel = True
            Chart_DVCategory.Series(SeriesName).ChartType = MyChartType
            'remove the grid lines
            Chart_DVCategory.ChartAreas(0).AxisX.MajorGrid.LineWidth = 0
            Chart_DVCategory.ChartAreas(0).AxisY.MajorGrid.LineWidth = 0
            'dock the legend at the top of the chart
            Chart_DVCategory.Legends("Legend1").Docking = Docking.Top
            'set the tick to 1 so it shows all the items
            Chart_DVCategory.ChartAreas(0).AxisX.Interval = 1
    
            If ThisListBox.Items.Count > 10 Then
                Chart_DVCategory.ChartAreas(0).AxisX.LabelStyle.Angle = -90
            Else
                Chart_DVCategory.ChartAreas(0).AxisX.LabelStyle.Angle = 0
            End If
    
           MyQuery = " Select Distinct MainCategory, 
                                COUNT(MainCategory) As SumCount 
                                 From
                                (
                                SELECT Distinct [case id],
                                    LEFT(DEVIATION_CATEGORY, 
    	                            LEN(DEVIATION_CATEGORY) - CHARINDEX(': ', REVERSE(DEVIATION_CATEGORY))) As MainCategory
                                FROM DMS_Deviation_Data Where DEVIATION_CATEGORY <> '' And Status ='Closed'
                                Group By DEVIATION_CATEGORY, [case id]
                                ) Temp
                                Group By MainCategory 
                                Order By MainCategory ASC"
    
                    TempTable = GetMyDataTable(MyQuery)
                    If TempTable.Rows.Count > 0 Then
                        For Each Drow As DataRow In TempTable.Rows
                            Chart_DVCategory.Series(0).Points.AddXY(Drow.Item("MainCategory").ToString, CInt(Drow.Item("SumCount")))
                        Next Drow
    
                    End If
    
            Chart_DVCategory.DataManipulator.Sort(PointSortOrder.Descending, SeriesName)
    
        End Sub
    What am I doing wrong?

  2. #2
    Addicted Member
    Join Date
    Jun 2018
    Posts
    253

    Re: Chart is cutting the top of bars, but only sometimes

    Hi Grand,

    I don't see anything right off.

    Try removing this line:

    Chart_DVCategory.ChartAreas(0).AxisX.Interval = 1


    Can you reproduce the problem without using the dbase ie just use a simple list with the four values that give the problem. Its hard to play with the problem if we don't have the data to reproduce it.

    On the problem data set the yaxis max over the max ie to 500. Then does it plot?

    PS Is Drow.Item("MainCategory") an integer or what? Why to string? Again, replace this with real integer values ie (1, 33) (2, 54) not using dbas ... then do you get the problem?
    Last edited by tommytwotrain; Apr 17th, 2019 at 07:56 AM.

  3. #3
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,062

    Re: Chart is cutting the top of bars, but only sometimes

    Don't see anything in that code that would cause that. It does seem like AxisY.Maximum is set to 6 for some reason. Show all the Designer code for the chart. Maybe you somehow accidentally changed something in there.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2018
    Posts
    244

    Re: Chart is cutting the top of bars, but only sometimes

    Thank you both for help and pointing to possible directions.
    I did those things you mentioned but the result was the same and random; no pattern or a link to what situation might cause it, or at least I could not see any.

    However, I added this line to the code just after the values were added to the series and the problem does not show itself; at least for now:

    Code:
    Chart_DVCategory.ChartAreas(0).RecalculateAxesScale()
    I think the code just descale the chart. I didn't know it should be necessary but for now the problem is gone.

    Thanks again for help.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2018
    Posts
    244

    Re: Chart is cutting the top of bars, but only sometimes

    Quote Originally Posted by tommytwotrain View Post
    Hi Grand,

    PS Is Drow.Item("MainCategory") an integer or what? Why to string? Again, replace this with real integer values ie (1, 33) (2, 54) not using dbas ... then do you get the problem?
    Just saw this after I posted my progress.
    That is an string and I use it as the name of each column that shows up just underneath each of them. Should it be an integer? How will I then produce the chart s shown in my post #1 with names of each column?

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