Question Custom control with chart not displaying

bulsatar

Member
Joined
Mar 4, 2012
Messages
8
Programming Experience
1-3
Morning Everyone,

I am making a custom control that only has a chart on it right now. It has 1 sub for initialization. I have added this control to a form and passed information to the control on form load. No matter what I do, I can see the initial chart on the custom control in display mode however when added to the form, I can never get the chart to show up. I have even taken code straight from the net that was labeled as an answer that didn't work. So...

Here is the code on my custom control that only has a chart control:
VB.NET:
Public Class dashpart



    Public Sub init(ByVal pLables As Hashtable, ByVal pCharttype As SeriesChartType, ByVal pSeriesData() As DataTable)
        'hash: title,xlable,ylable,series1, series2,,,


        Chart1.Series.Clear()
        For Each seriesdt As DataTable In pSeriesData
            Dim series As New Series
            series.Name = pLables("series1")
            series.ChartType = pCharttype
            series.Points.DataBind(seriesdt, "Value", "Date", "")
            Chart1.Series.Add(series)
        Next
        With Chart1.ChartAreas(0)
            .AxisX.Interval = 10
            .AxisX.Title = "Value"
            .AxisY.Title = "Dates"
        End With
    End Sub


End Class

And here is the code on my form that only has the dashpart on it that I can't get to display anything:
VB.NET:
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim temphash As Hashtable = Nothing
        temphash.Add("title", "tester")
        temphash.Add("series1", "Innards")


        Dim dt() As DataTable = Nothing
        dt(0).Columns.Add("Date")
        dt(0).Columns.Add("Value")
        Dim dr1 As DataRow = dt(0).NewRow
        Dim dr2 As DataRow = dt(0).NewRow
        Dim dr3 As DataRow = dt(0).NewRow
        dr1.Item("Date") = DateAdd(DateInterval.Month, -5, Now)
        dr1.Item("Value") = 100
        dr2.Item("Date") = DateAdd(DateInterval.Month, -8, Now)
        dr2.Item("Value") = 500
        dr3.Item("Date") = DateAdd(DateInterval.Year, -1, Now)
        dr3.Item("Value") = 300
        dt(0).Rows.Add(dr1) : dt(0).Rows.Add(dr2) : dt(0).Rows.Add(dr3)




        Dashpart1.init(temphash, DataVisualization.Charting.SeriesChartType.Bar, dt)
    End Sub
End Class

Thanks for any help you can give!!
 
nevermind. Did a good more searching and playing and got something that works decently:

code for the custom control:
VB.NET:
Public Sub init(ByVal pLables As Hashtable, ByVal pCharttype As SeriesChartType, ByVal pSeriesData As List(Of DataTable))        'hash: heading,title,xlabel,ylabel,series1, series2,,,


        Me.Label1.Text = pLables("heading")
        Chart1.Series.Clear()
        Dim i As Integer = 0
        For Each dt As DataTable In pSeriesData
            Dim currSeries As Series = Chart1.Series.Add(pLables("series" & CStr(i + 1)))
            With currSeries
                .Name = pLables("series" & CStr(i + 1))
                .Font = New Font("Arial", 8, FontStyle.Bold)
                .Color = GetNewColor()
                .IsValueShownAsLabel = True
                .LabelBackColor = Color.Transparent
                .LabelForeColor = Color.Black
                .Points.DataBind(dt.DefaultView, dt.Columns(0).ColumnName, dt.Columns(1).ColumnName, "")
                .ChartType = pCharttype


            End With
            i += 1
        Next


    End Sub


    Private Function GetNewColor() As Color
        Dim tempColor As Color = Color.Aquamarine
        Dim gen As Random = New Random
        tempColor = Color.FromArgb(gen.Next(0, 254), gen.Next(0, 254), gen.Next(0, 254), gen.Next(0, 254))
        Return tempColor
    End Function

and an example of how to initialize the part:
VB.NET:
Dim temphash As New Hashtable        Dim dt As New List(Of DataTable)
        temphash.Add("title", "tester")
        temphash.Add("series1", "Innards")


        dt.Add(New DataTable)
        dt(0).Columns.Add("Date")
        dt(0).Columns.Add("Value")
        Dim dr1 As DataRow = dt(0).NewRow
        Dim dr2 As DataRow = dt(0).NewRow
        Dim dr3 As DataRow = dt(0).NewRow
        dr1.Item("Date") = DateAdd(DateInterval.Month, -5, Now)
        dr1.Item("Value") = 100
        dr2.Item("Date") = DateAdd(DateInterval.Month, -8, Now)
        dr2.Item("Value") = 500
        dr3.Item("Date") = DateAdd(DateInterval.Year, -1, Now)
        dr3.Item("Value") = 300
        dt(0).Rows.Add(dr1) : dt(0).Rows.Add(dr2) : dt(0).Rows.Add(dr3)


        dashpartTest.init(temphash, DataVisualization.Charting.SeriesChartType.Pie, dt)
 
Back
Top