Adding the chart series dynamically using an array

Thread is closed for posting
2 posts, 0 answers
  1. ervin
    ervin avatar
    22 posts
    Member since:
    May 2011

    Posted 31 May 2011 Link to this post

    Hi,
    My chart has more than one series (the number always changes).
    I want to add these series dynamically into my chart (sometimes 2 sometimes 5 series). I tried to use an array but it did not work. How can I add the (changing number) chart series dynamically? and what is the problem with the array? (Please see the code below)

    Thanks,
    Ervin

     

    Dim rowNumber As Integer = ds.Tables(0).Rows.Count
    Dim myChartSeries(rowNumber - 1) As ChartSeries
    For index As Integer = 0 To rowNumber - 1
    With myChartSeries(index)

    .Name = s1

    .Appearance.TextAppearance.TextProperties.Color = Color.Blue

    .Type = ChartSeriesType.Line

    .Appearance.LabelAppearance.Visible = True

    .Appearance.PointMark.Dimensions.AutoSize = False

    .Appearance.PointMark.Dimensions.Width = 7

    .Appearance.PointMark.Dimensions.Height = 7

    .Appearance.PointMark.FillStyle.MainColor = Color.Black

    .Appearance.PointMark.Visible = True
    For index2 As Integer = 0 To 5
    Dim
    mychartSeriesItem As Integer = Int(ds.Tables(0).Rows(0).Item(index2 + 1))

     

     

    myChartSeries(index2).AddItem(mychartSeriesItem)
    Next

    End With

    chart.AddChartSeries(myChartSeries(index))
    Next

    chart.DataBind()

  2. ervin
    ervin avatar
    22 posts
    Member since:
    May 2011

    Posted 01 Jun 2011 Link to this post

    Ok, I found it.
    I forgot a very basic line... When you add the below line, it works...
    myChartSeries(index) = New ChartSeries()

    Thanks,
    Ervin

Back to Top