Hi Marc,
The approach to sampling is very straight forward - the following code implements the algorithm proposed above:
// init array with some random data
double[] yValues = new double[100000];
double[] xValues = new double[100000];
for (int i = 0; i < 100000; i++)
{
yValues[i] = Math.Sin((double)i / 10000) * 100;
xValues[i] = i;
}
//1. Calculate min max
double minX = xValues[0];
double maxX = xValues[0];
double minY = xValues[0];
double maxY = xValues[0];
for (int i = 0; i < 100000; i++)
{
minX = Math.Min(minX, xValues[i]);
maxX = Math.Max(maxX, xValues[i]);
minY = Math.Min(minY, yValues[i]);
maxY = Math.Max(maxY, yValues[i]);
}
//2. calculate box
double boxSemiWidth = (maxX - minX) / 200;
double boxSemiHeight = (maxY - minY) / 200;
//3. sample data
int boxCount = 0;
double boxStartX = 0;
double boxStartY = 0;
double boxSumX = 0;
double boxSumY = 0;
NLineSeries line = new NLineSeries();
line.UseXValues = true;
line.DataLabelStyle.Visible = false;
for (int i = 0; i < xValues.Length; i++)
{
if (boxCount != 0)
{
// check if we can add current to box
if (Math.Abs(xValues[i] - boxStartX) < boxSemiWidth &&
Math.Abs(yValues[i] - boxStartY) < boxSemiHeight)
{
boxSumX += xValues[i];
boxSumY += yValues[i];
boxCount++;
continue;
}
// otherwise output current box
line.Values.Add(boxSumY / boxCount);
line.XValues.Add(boxSumX / boxCount);
}
// start new box
boxSumX = xValues[i];
boxSumY = yValues[i];
boxStartX = xValues[i];
boxStartY = yValues[i];
boxCount = 1;
}
if (boxCount > 0)
{
// output trailing box
line.Values.Add(boxSumY / boxCount);
line.XValues.Add(boxSumX / boxCount);
}
// add line to chart
NChart chart = nChartControl1.Charts[0];
chart.Series.Add(line);
Regarding the HTML problem. When you have many data points with interactivity the control will generate an image map area for each one of them. This can lead to a huge HTML image map that will choke any browser. Therefore you need to resample in order to reduce the generated image map.
Hope this helps...