Bob;
Thanks very much for posting your solution -- I modified the code you provided to suit our circumstances and the resulting method does everything I'd been hoping for. My callback class looks like this:
public class NCustomPaintCallback : NPaintCallback {
private NChart m_Chart;
private NChartControl m_Control;
private ConfidenceIntervalCalculator _confidenceIntervalCalculator = null;
public NCustomPaintCallback( NChartControl control,
NChart chart,
ConfidenceIntervalCalculator p_confidenceIntervalCalculator ) {
m_Chart = chart;
m_Control = control;
_confidenceIntervalCalculator = p_confidenceIntervalCalculator;
}
/// Occurs after the panel is painted.
public override void OnAfterPaint( NPanel panel, NPanelPaintEventArgs eventArgs ) {
NGraphics graphics = eventArgs.Graphics;
NFillStyle fill = new NColorFillStyle( Color.FromArgb( 125, Color.Red ) );
NScale2DToViewTransformation transform = new NScale2DToViewTransformation( m_Control.View.Context,
m_Chart,
(int)StandardAxis.PrimaryX,
(int)StandardAxis.PrimaryY );
NPointF[] points = new NPointF[4]; // our polynomial
for ( int i = 0; i < _confidenceIntervalCalculator.lowerConfidenceBandPointList.Count-1; i++ ) {
points[0] = new NPointF( Convert.ToSingle( _confidenceIntervalCalculator.upperConfidenceBandPointList[i].X ),
Convert.ToSingle( _confidenceIntervalCalculator.upperConfidenceBandPointList[i].Y ) );
points[1] = new NPointF( Convert.ToSingle( _confidenceIntervalCalculator.upperConfidenceBandPointList[i + 1].X ),
Convert.ToSingle( _confidenceIntervalCalculator.upperConfidenceBandPointList[i + 1].Y ) );
points[2] = new NPointF( Convert.ToSingle( _confidenceIntervalCalculator.lowerConfidenceBandPointList[i + 1].X ),
Convert.ToSingle( _confidenceIntervalCalculator.lowerConfidenceBandPointList[i + 1].Y ) );
points[3] = new NPointF( Convert.ToSingle( _confidenceIntervalCalculator.lowerConfidenceBandPointList[i].X ),
Convert.ToSingle( _confidenceIntervalCalculator.lowerConfidenceBandPointList[i].Y ) );
for ( int j = 0; j < points.Length; j++ ) {
NVector2DD vecScalePoint = new NVector2DD( points[j].X, points[j].Y );
NPointF viewPoint = new NPointF( );
transform.Transform( vecScalePoint, ref viewPoint );
points[j] = viewPoint;
}
graphics.PaintPolygon( fill, null, points );
}
}
}
So now I'm completely happy with the plot, with only one exception. When I now use the mouse to zoom in on my resulting graphic (using the NDataZoomTool) the fill colors wash over the boundaries of the axes (that is, everything scales correctly, but the color doesn't stop at the axes boundaries -- instead it continues all the way to the edge of the screen). Is there a way to force the filled area I'm adding to obey the boundaries of the axes in a zoomed view, or to I need to go in by hand and decide which portions of which polynomials should properly be visible, and then only use the PaintPolygon method on that restricted area?
Either way, thanks for your original solution. The graphic produced by my modified code is really quite nice, and a vast improvement over my original line plot.
Ben