简体   繁体   中英

ZedGraph plotting large amount of data

Hi.

            PointPairList list = new PointPairList();
            LineItem myCurve = myPane.AddCurve("My Curve", list, Color.Blue,
                                    SymbolType.None);
            for (int x = y; x < buffer.Length; x++)
            {
                list.Add(x, buffer[x]);
            }

I have a file its size is 40 mb. I am reading the bytes and writing the data into buffer so buffer.lenght gets a large number. Thus program throws out of memory exception because of long for loop. How can i draw all bytes without taking out of memory exception.?

You will need to pre-process the byte array generating a smaller data set that is 2x the maximum horizontal width or your chart.

To display a chart that is maxWidth pixels wide you will do something like this .

int window = (buffer.Length / maxWidth) + 1;

for (int x = 0; x < buffer.Length; x += window)
{
    double min = double.MaxValue;
    double max = double.MinValue;

    for (int j = 0; j < window; j++)
    {
        int index = x + j;

        if (index < buffer.Length)
        {
            double value = buffer[x+j];
            if (value < min)
            {
                min = value;
            }

            if (value > max)
            { 
                max = value;
            }
        }
    }

    list.Add(x, min);
    list.Add(x + (window - 1), max);
}

If you zoom in you need to recalculate the point list so that you do not end up with the saw tooth line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM