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?

    <FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> series </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Chart.ClusteredBarSeries()


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> label </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Chart.LabelArea()


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> model </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Chart.ChartModel()


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> plotArea </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Chart.YPlotArea()


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> ChartHeight </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Integer

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> legend </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Chart.LegendArea()


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>For</FONT></FONT><FONT size=2> i </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Integer</FONT></FONT><FONT size=2> = 1 </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>To</FONT></FONT><FONT size=2> DS.Tables(9).Columns.Count - 1


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> aSeries(i) </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> FarPoint.Win.Chart.BarSeries


    aSeries(i) = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Chart.BarSeries


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With</FONT></FONT><FONT size=2> 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 = </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"#,##0"

    </FONT></FONT><FONT size=2>

    .LabelVisible = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>True

    </FONT></FONT><FONT size=2>

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


    series.Series.Add(aSeries(i))


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Next

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With</FONT></FONT><FONT size=2> label


    .Text = </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"Tank Usage by Vintage / Size Family"</FONT></FONT><FONT size=2> & vbNewLine & </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Me</FONT></FONT><FONT size=2>.txtWhseDesc.Text & vbNewLine & StartDate & </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>" - "</FONT></FONT><FONT size=2> & </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Me</FONT></FONT><FONT size=2>.fdtDate.Text


    .Location = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> PointF(0.55F, 0.02F)


    .AlignmentX = 0.8F


    .AlignmentY = 0.0F


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With</FONT></FONT><FONT size=2> legend


    .Location = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> PointF(0.95F, 0.06F)


    .AlignmentX = 1.0F


    .AlignmentY = 0.5F


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With</FONT></FONT><FONT size=2> plotArea


    .Location = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> PointF(0.1, 0.1F) </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>'(left/right, up/down)

    </FONT></FONT><FONT size=2>

    .Size = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> SizeF(0.8F, 0.8F)


    .Series.Add(series)


    .Vertical = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>False

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With</FONT></FONT><FONT size=2> model


    .LabelAreas.Add(label)


    .PlotAreas.Add(plotArea)


    .LegendAreas.Add(legend)


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With</FONT></FONT><FONT size=2> fpsByVintage.ActiveSheet


    .ColumnHeader.Visible = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>False

    </FONT></FONT><FONT size=2>

    .RowHeader.Visible = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>False

    </FONT></FONT><FONT size=2>

    .PrintInfo.UseMax = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>False

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With</FONT></FONT><FONT size=2> fpsByVintage_Sheet1_SpreadChart1


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


    .Size = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> Size(750, ChartHeight)


    .Model = model


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>With

    </FONT></FONT>
  • Replied 8 September 2017, 2:46 pm EST

    I just realized I was missing: <FONT size=2>

    .Values.DataSource = DS.Tables(9)


     Now my chart works fine <img src="/emoticons/emotion-2.gif" alt="Big Smile" />

    </FONT>
Need extra support?

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

Learn More

Forum Channels