Thanks. Works like a charm. I have pasted my code for anyone that wants it:
using System;
using System.Drawing;
using System.Collections.Generic;
using NationalInstruments.UI;
using NationalInstruments.Analysis.Math;
namespace com.Linear.ATE.Data
{
public class BarPlot : WaveformPlot
{
private Color color;
private int transparency = 50;
private List<RectangleF> bars = new List<RectangleF>();
private bool spline = true;
public BarPlot(XAxis xAxis, YAxis yAxis, Color color, int transparency) : base(xAxis, yAxis)
{
this.color = color;
this.transparency = transparency;
}
public bool UseSpline
{
get { return spline; }
set { spline = value; }
}
public Color Color
{
get { return color; }
set { color = value; }
}
public int Transparency
{
get { return transparency; }
set { transparency = value; }
}
public List<RectangleF> Bars
{
get { return bars; }
}
protected override void OnAfterDraw(AfterDrawXYPlotEventArgs e)
{
base.OnAfterDraw(e);
Color c = Color.FromArgb(255*transparency/100, color);
Brush barBrush = new SolidBrush(c);
Graphics g = e.Graphics;
// Clip the data buffer to the points that are in the current range.
double[] xData = null, yData = null;
ClipDataPoints(out xData, out yData);
List<double> x = new List<double>();
List<double> y = new List<double>();
bars.Clear();
for (int i = 0; i < xData.Length; ++i)
{
// Map the current data point to the corresponding screen coordinate.
PointF dataPoint = MapDataPoint(e.Bounds, xData[i], yData[i]);
PointF top = this.MapDataPoint(e.Bounds, xData[i], yData[i]);
PointF bottom = this.MapDataPoint(e.Bounds, xData[i], 0.0);
RectangleF r = new RectangleF(top.X + 1,
top.Y,
(float)(e.Bounds.Width / xData.Length) - 1,
bottom.Y);
x.Add(r.X + r.Width/2);
y.Add(r.Y);
g.FillRectangle(barBrush, r);
bars.Add(r);
}
if (spline)
{
double[] xVals = x.ToArray();
double[] yVals = y.ToArray();
CurveFit.CubicSplineFitInPlace(xVals, yVals, 2.0);
PointF[] points = new PointF[xVals.Length];
for (int index = 0; index < xVals.Length; index++)
points[index] = new PointF((float)xVals[index], (float)yVals[index]);
g.DrawLines(new Pen(color, 2), points);
}
}
}
}