/// <summary>
        /// Process the series to build the chart data structure.
        /// </summary>
        /// <param name="dataset">The dataset.</param>
        /// <returns>Data series</returns>
        protected virtual ISeries CreateSeries(DataStream dataset)
        {
            var xI = dataset.FieldNames.IndexOf("x");
            var yI = dataset.FieldNames.IndexOf("y");
            var wI = dataset.FieldNames.IndexOf("w");
            var hI = dataset.FieldNames.IndexOf("h");

            var x = new List<TReal>();
            var y = new List<TReal>();
            var w = new List<TReal>();
            var h = new List<TReal>();

            //var atts = new List<object>();
            //var nameIndices = Enumerable.Range(0, dataset.FieldNames.Count).Except(new[] { xI, yI, wI, hI }).ToArray();

            foreach (var dataStreamValue in dataset.Stream)
            {
                //atts.AddRange(from c in nameIndices select dataStreamValue.Values[c]);
                x.Add((TReal)dataStreamValue.Values[xI]);
                y.Add((TReal)dataStreamValue.Values[yI]);
                w.Add((TReal)dataStreamValue.Values[wI]);
                h.Add((TReal)dataStreamValue.Values[hI]);
            }

            var series = new Series1(x, y, w, h);

            //var names = nameIndices.Select(i => dataset.FieldNames[i]).ToArray();
            //var types = nameIndices.Select(i => dataset.FieldTypes[i]).ToArray();
            //var series = new Series2(x, y, w, h, names, types, atts);

            var adapter = new RectangleRenderableSeries(series);
            chart.RenderableSeries.Add(adapter);
            brd.Visibility = Visibility.Collapsed;

            return series;
        }
 /// <summary>
 /// Generates the data stream like service can deliver.
 /// </summary>
 /// <param name="length">The length.</param>
 /// <returns>data stream</returns>
 private DataStream GenerateDataStream(int length)
 {
     var adt = 20;
     var names = new[] { "x", "y", "w", "h", "type" };
     var types = new[] { typeof(TReal), typeof(TReal), typeof(TReal), typeof(TReal), typeof(string) };
     Array.Resize(ref names, names.Length+adt);
     Array.Resize(ref types, names.Length + adt);
     for (int i = 5; i < names.Length; i++)
     {
         names[i] = "Field" + i;
         types[i] = typeof (double);
     }
     var stream = new DataStream(names, types, EnumerateDataStreamValues(length, adt));
     return stream;
 }
        protected override ISeries CreateSeries(DataStream dataset)
        {
            var xI = dataset.FieldNames.IndexOf("x");
            var yI = dataset.FieldNames.IndexOf("y");
            var wI = dataset.FieldNames.IndexOf("w");
            var hI = dataset.FieldNames.IndexOf("h");

            var nameIndices = Enumerable.Range(0, dataset.FieldNames.Count).Except(new[] { xI, yI, wI, hI }).ToArray();
            var names = nameIndices.Select(i => dataset.FieldNames[i]).ToArray();
            var types = nameIndices.Select(i => dataset.FieldTypes[i]).ToArray();

            // README Check series
            var series = new Series4(names, types);

            const int chunkSize = 1000000;
            var x = new List<TReal>(chunkSize); var y = new List<TReal>(chunkSize);
            var h = new List<TReal>(chunkSize); var w = new List<TReal>(chunkSize);
            var atts = new List<object>(chunkSize*nameIndices.Length);

            VisualStateManager.GoToState(this, "Loading", true);

            Task.Run(() =>
            {
                try
                {
                    var bufferedChunks = dataset.Stream.Buffer(chunkSize, false);
                    foreach (var dataStreamValues in bufferedChunks)
                    {
                        x.Clear();
                        y.Clear();
                        w.Clear();
                        h.Clear();
                        atts.Clear();
                        foreach (var dataStreamValue in dataStreamValues)
                        {
                            atts.AddRange(from c in nameIndices select dataStreamValue.Values[c]);
                            x.Add((TReal) dataStreamValue.Values[xI]);
                            y.Add((TReal) dataStreamValue.Values[yI]);
                            w.Add((TReal) dataStreamValue.Values[wI]);
                            h.Add((TReal) dataStreamValue.Values[hI]);
                        }

                        using (chart.SuspendUpdates())
                        {
                            series.Append(x, y, w, h, atts);
                        }

                        UpdateStatus();
                    }

                    Thread.Sleep(2000);
                    Dispatcher.InvokeAsync(() => brd.Visibility = Visibility.Collapsed);
                }
                catch(Exception e)
                {
                    txtLoadingStatus.Text = $"Error loading data: {e.Message}";
                    progressBar.Value = 0;
                    Trace.WriteLine("Error: " + e);
                }
            });

            // README Check adapter
            var adapter = new RectangleRenderableSeries3(series);
            chart.RenderableSeries.Add(adapter);

            return series;
        }