Search code examples
scichart

SciChart: ColumnChart - DataSeries.Append


A potential problem I noticed in SciChart for WPF

  • take the standard example for ColumnChart from SDK (2D Charts - Column Chart)
  • build and run; the result is as below: enter image description here

  • make the following code changes (see (1) and (2))

    private void ColumnChartExampleViewOnLoaded(object sender, RoutedEventArgs e)
    {
    
        var dataSeries = new XyDataSeries<double, double> {SeriesName = "Histogram"};
    
        var yValues = new double[] { 0.1, 0.2, 0.4, 0.8, 1.1, 1.5, 2.4, 4.6, 8.1, 11.7, 14.4, 16.0, 13.7, 10.1, 6.4, 3.5, 2.5, 1.4, 0.4, 0.1};
    
        using (this.sciChart.SuspendUpdates())
        {
            for (int i = 0; i < yValues.Length; i++)
            {
                // DataSeries for appending data
                dataSeries.Append(i, yValues[i]);
            }
    
            this.columnSeries.DataSeries = dataSeries;
            this.columnSeries.DataSeries.AcceptsUnsortedData = true; //(1)
        }
    
        dataSeries.Append(0, 1); //(2)
        this.sciChart.ZoomExtents();
    }
    
  • and here is the result: enter image description here

I.e. if I use Append method for the X val which already exists - the UI bars are changing to the lines. I do not know if it is expected behavior or not but for my case I'm updating the Histogram on fly and quite often same X value is having new Y value(s). As a result - the UI behavior confuses... I found workaround for my case (I'm using the Update method since X and index is the same for my case) so this is just a notice.

I'm not sure will you change the behavior or not - just sharing my experience for now...


Solution

  • SciChart's column series automatically calculates the width of the data-points based on the columns you have available.

    If you have columns 0,1,2,3,4,5,6,7,8,9 ...then add a new column at position 0, this calculation goes haywire.

    Ways of avoiding this side-effect are:

    • Update items rather than append new columns with overlapping values
    • Override column width calculation using the properties FastColumnRenderableSeries.UseUniformWidth and FastColumnRenderableSeries.DataPointWidth
    • (Advanced) Override column width calculation by overriding GetDataPointWidth() method.

    Find out more how the Column series works at the SciChart WPF Documentation page.