Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
710
Line series not always drawing when adding in code behind.
posted

Hi, I have the need to add an unknown number of charts each with an unknown number of line series on them. I'm doing it on code behind and the general functionality is fine. However, I'm finding some series which are definitely added to the chart do not draw. If I rebuild over and over they will eventually draw. I have attached a simplified version of the production application which also displays this anomaly.

Build it once and the lower chart has one line series - it should have 2.

After a random number of rebuilds the second series shows up

Cheers

PeterGenerateChart.zip

  • 1295
    Verified Answer
    Offline posted

    Hello Peter,

    Thank you for posting in Infragistics forum.

    The reason why the bottom chart shows only one series is that the two series instances are being assigned the data that have the same data points. The first series is not visible since the second one is being drawn on top of the first one.

    It looks like your SimpleDataCollection class provides the same data to these two line series.
    This happens because you instantiate and initialize a random number generator each time you create the chart data.

    A quick fix I can suggest is to use a static instance for Random object and reuse it each time you create the chart data.

    ------------------
        public class SimpleDataCollection : ObservableCollection<SimpleDataPoint>
        {
            static Random random = new Random();
            public SimpleDataCollection()
            {
                //Do not recreate a random instance, but reuse it.
                //Random random = new Random();
    .....
            }
        }
    ------------------

    Random  Class
    https://docs.microsoft.com/en-us/dotnet/api/system.random?redirectedfrom=MSDN&view=netframework-4.8