Re: Charts controls with GDI+
If you add image tags around the image links they will display inline. [ I M G ] and [ / I M G ] without the spaces, of course. You will need the full name from imgur ie. https://imgur.com/y0ehIkQ.gif
https://www.vbforums.com/images/ieimages/2025/04/1.gif
Re: Charts controls with GDI+
Hello Yereverluvinuncleber ,
Thanks for the guidance.
I have a challenge with the ucChartBar. I need to display departments by their initials in X-axis and the employee count in the Y-axis for both the Males and Females using the bar chart. Allow me to attach both the code and the data to be analyzed by the graph here. The issue I have is that the code stops in the function GetMax() of the ucChartBar with error "Object is no longer valid". Can you assist me go past this error and display the graph.
Below is the code
Code:
Private Sub DisplayGenderGraph()
Dim VALUEX As Collection
Dim VALUEY As Collection
Dim CustomColors As Collection
Dim i As Long, j As Long
Dim Min As Single
Dim Max As Single
Dim Palette() As String
Dim strDEPTINITIAL() As String
'Display Employee Count by Gender per Department
ucChartBar1.Clear
'determine unique departments
myString = "SELECT TOP (100) PERCENT DEPARTMENT AS DEPARTMENTQ, DEP_INITIAL " _
& "FROM DEPARTMENT " _
& "WHERE (DEPT_ACTIVE = 1) " _
& "ORDER BY DEP_INITIAL"
If rsTemp.State = adStateOpen Then rsTemp.Close
rsTemp.Open myString, Maincn, adOpenKeyset, adLockOptimistic
If rsTemp.RecordCount > 0 Then
intX = rsTemp.RecordCount
strX = "'"
Set VALUEX = New Collection
For i = 0 To intX - 1
'VALUEX.Add rsTemp!DEP_INITIAL
strX = strX & rsTemp!DEP_INITIAL & "','"
If rsTemp.EOF = False Then rsTemp.MoveNext Else Exit For
Next
strX = Left(strX, Len(strX) - 2)
strDEPTINITIAL = Split(strX, ",")
For i = 0 To UBound(strDEPTINITIAL)
VALUEX.Add strDEPTINITIAL(i)
Next i
ucChartBar1.AddAxisItems VALUEX, False, 0, 1
End If
Palette = Split("&H004744E3, &H003DB0EF, &H00ABA56C, &H0048BDBF, &H004D91F4, &H007450, &H0050C187, &HC0C0FF, &HFFFFC0, &H80FFFF, &HFF8D11, &HA744E0, &H376CE6, &H40AB1A, &H7B006B, &H400000, &H404080, &H80C0FF, &HC0C0C0, &HFF00FF, &HC0FFC0, &H8080FF, &H80&", ",")
'Determine unique genders
myString = "SELECT DISTINCT GENDER AS GENDERM FROM PERSONNEL_MASTER ORDER BY GENDER"
If rs.State = adStateOpen Then rs.Close
rs.Open myString, Maincn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
For i = 1 To rs.RecordCount
NameX = rs!GENDERM
myString = "SELECT TOP (100) PERCENT DEPARTMENT, GENDER, EMPCOUNT, PERIOD, PYEAR, DEP_INITIAL " _
& "FROM EMPLOYEE_COUNT_GENDER_TEMP " _
& "WHERE (GENDER = '" & rs!GENDERM & "') " _
& "ORDER BY DEP_INITIAL"
If rsTemp.State = adStateOpen Then rsTemp.Close
rsTemp.Open myString, Maincn, adOpenKeyset, adLockOptimistic
Set VALUEY = New Collection
For j = 0 To intX - 1
VALUEY.Add rsTemp!EMPCOUNT
rsTemp.MoveNext
Next
ucChartBar1.AddSerie NameX, CLng(Palette(i)), VALUEY
rs.MoveNext
Next i
End If
End Sub
Error generated can be seen here:
https://imgur.com/l0tiKyn
Point where error occurs in the user control code:
https://imgur.com/SCMlXG9
Data to be displayed in the ucChartBar
https://imgur.com/y0ehIkQ
I will really appreciate your support on this. I hope I have gotten it right now
Regards,
Nicholas.
Re: Charts controls with GDI+
Quote:
Originally Posted by
NOkello2002
Hello Yereverluvinuncleber ,
Thanks for the guidance.
I have a challenge with the ucChartBar. I need to display departments by their initials in X-axis and the employee count in the Y-axis for both the Males and Females using the bar chart. Allow me to attach both the code and the data to be analyzed by the graph here. The issue I have is that the code stops in the function GetMax() of the ucChartBar with error "Object is no longer valid". Can you assist me go past this error and display the graph.
Below is the code
Code:
Private Sub DisplayGenderGraph()
Dim VALUEX As Collection
Dim VALUEY As Collection
Dim CustomColors As Collection
Dim i As Long, j As Long
Dim Min As Single
Dim Max As Single
Dim Palette() As String
Dim strDEPTINITIAL() As String
'Display Employee Count by Gender per Department
ucChartBar1.Clear
'determine unique departments
myString = "SELECT TOP (100) PERCENT DEPARTMENT AS DEPARTMENTQ, DEP_INITIAL " _
& "FROM DEPARTMENT " _
& "WHERE (DEPT_ACTIVE = 1) " _
& "ORDER BY DEP_INITIAL"
If rsTemp.State = adStateOpen Then rsTemp.Close
rsTemp.Open myString, Maincn, adOpenKeyset, adLockOptimistic
If rsTemp.RecordCount > 0 Then
intX = rsTemp.RecordCount
strX = "'"
Set VALUEX = New Collection
For i = 0 To intX - 1
'VALUEX.Add rsTemp!DEP_INITIAL
strX = strX & rsTemp!DEP_INITIAL & "','"
If rsTemp.EOF = False Then rsTemp.MoveNext Else Exit For
Next
strX = Left(strX, Len(strX) - 2)
strDEPTINITIAL = Split(strX, ",")
For i = 0 To UBound(strDEPTINITIAL)
VALUEX.Add strDEPTINITIAL(i)
Next i
ucChartBar1.AddAxisItems VALUEX, False, 0, 1
End If
Palette = Split("&H004744E3, &H003DB0EF, &H00ABA56C, &H0048BDBF, &H004D91F4, &H007450, &H0050C187, &HC0C0FF, &HFFFFC0, &H80FFFF, &HFF8D11, &HA744E0, &H376CE6, &H40AB1A, &H7B006B, &H400000, &H404080, &H80C0FF, &HC0C0C0, &HFF00FF, &HC0FFC0, &H8080FF, &H80&", ",")
'Determine unique genders
myString = "SELECT DISTINCT GENDER AS GENDERM FROM PERSONNEL_MASTER ORDER BY GENDER"
If rs.State = adStateOpen Then rs.Close
rs.Open myString, Maincn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
For i = 1 To rs.RecordCount
NameX = rs!GENDERM
myString = "SELECT TOP (100) PERCENT DEPARTMENT, GENDER, EMPCOUNT, PERIOD, PYEAR, DEP_INITIAL " _
& "FROM EMPLOYEE_COUNT_GENDER_TEMP " _
& "WHERE (GENDER = '" & rs!GENDERM & "') " _
& "ORDER BY DEP_INITIAL"
If rsTemp.State = adStateOpen Then rsTemp.Close
rsTemp.Open myString, Maincn, adOpenKeyset, adLockOptimistic
Set VALUEY = New Collection
For j = 0 To intX - 1
VALUEY.Add rsTemp!EMPCOUNT
rsTemp.MoveNext
Next
ucChartBar1.AddSerie NameX, CLng(Palette(i)), VALUEY
rs.MoveNext
Next i
End If
End Sub
Error generated can be seen here:
https://www.vbforums.com/images/ieimages/2025/04/1.jpg
Point where error occurs in the user control code:
https://www.vbforums.com/images/ieimages/2025/04/1.jpg
Data to be displayed in the ucChartBar
https://www.vbforums.com/images/ieimages/2025/04/1.jpg
I will really appreciate your support on this. I hope I have gotten it right now
Regards,
Nicholas.
Hi
I did some mods to the control since I also had problems with it but don't know if it would fix your problem. Please do a simpler example without using database (just adding some data manually) and I'll try to run you code with my modified control.
Regards