Dynamic series in chart

Posted by: ginacresse on 8 September 2017, 2:46 pm EST

  • Posted 8 September 2017, 2:46 pm EST

    Is there a way to create a chart with a dynamic set of series?  I want to bind to a dataset that may return any number of columns and I'd like each column to be a separate bar on the chart.  So far I can't find a way to do it dynamically.  Can it be done?


     Thanks

  • Replied 8 September 2017, 2:46 pm EST

    Hello,

    Spread has a ClusteredBarSeries collection to which you can add different bar series and each series is represented as a separate bar in the chart. This collection groups together two or more bar series, and shows the bars alongside each other horizontally clustered by series. For each series in the collection you can assign a different column in the dataset to be the series datasource, and it would represent each column with a different colored bar. I have created a sample depicting the same approach, in which two columns of a datatable are assigned to two different series and each series is represented as a separate colored bar on the chart. Kindly have a look at the sample. Please let me know if you have any queries further.

    Thanks,

    Manpreet Kaur.


    2011/09/chartplotarea.zip
  • Replied 8 September 2017, 2:46 pm EST

    I am new to the charting features of Farpoint, but it appears that your sample assumes a known number of series: Series1 and Series2.  My question is, how do I create the clustered bar chart when the number of bars (series) is an unknown?  I am trying the following code to use a series array, but I am not getting the correct results.  The legend appears correctly but I get no bars.  Is there a glaring mistake that I'm not seeing?


    Dim series As New FarPoint.Win.Chart.ClusteredBarSeries()


    Dim label As New FarPoint.Win.Chart.LabelArea()


    Dim model As New FarPoint.Win.Chart.ChartModel()


    Dim plotArea As New FarPoint.Win.Chart.YPlotArea()


    Dim ChartHeight As Integer


    Dim legend As New FarPoint.Win.Chart.LegendArea()


    For i As Integer = 1 To DS.Tables(9).Columns.Count - 1


    Dim aSeries(i) As FarPoint.Win.Chart.BarSeries


    aSeries(i) = New FarPoint.Win.Chart.BarSeries


    With aSeries(i)


    .Values.DataField = DS.Tables(9).Columns(i).ColumnName << I assume this code determines the value for the bars, but I get no bars. 


    .CategoryNames.DataSource = DS.Tables(9)


    .CategoryNames.DataField = DS.Tables(9).Columns(0).ColumnName


    .LabelNumberFormat = "#,##0"


    .LabelVisible = True


    .SeriesName = DS.Tables(9).Columns(i).ColumnName


    series.Series.Add(aSeries(i))


    End With


    Next


    With label


    .Text = "Tank Usage by Vintage / Size Family" & vbNewLine & Me.txtWhseDesc.Text & vbNewLine & StartDate & " - " & Me.fdtDate.Text


    .Location = New PointF(0.55F, 0.02F)


    .AlignmentX = 0.8F


    .AlignmentY = 0.0F


    End With


    With legend


    .Location = New PointF(0.95F, 0.06F)


    .AlignmentX = 1.0F


    .AlignmentY = 0.5F


    End With


    With plotArea


    .Location = New PointF(0.1, 0.1F) '(left/right, up/down)


    .Size = New SizeF(0.8F, 0.8F)


    .Series.Add(series)


    .Vertical = False


    End With


    With model


    .LabelAreas.Add(label)


    .PlotAreas.Add(plotArea)


    .LegendAreas.Add(legend)


    End With


    With fpsByVintage.ActiveSheet


    .ColumnHeader.Visible = False


    .RowHeader.Visible = False


    .PrintInfo.UseMax = False


    End With


    With fpsByVintage_Sheet1_SpreadChart1


    ChartHeight = DS.Tables(9).Rows.Count * 55


    .Size = New Size(750, ChartHeight)


    .Model = model


    End With

  • Replied 8 September 2017, 2:46 pm EST

    I just realized I was missing:

    .Values.DataSource = DS.Tables(9)


     Now my chart works fine Big Smile

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels