Hi Harry,
/// <summary>
/// Performs custom painting
/// </summary>
/// <param name="context"></param>
/// <param name="graphics"></param>
public void Paint2D(NChartRenderingContext2D context, NGraphics graphics)
{
NVector3DF vecView = new NVector3DF();
NVector3DF vecModel = new NVector3DF();
NScaleRuler rulerX = m_Chart.Axis(m_Series.HorizontalAxes[0]).Scale.Ruler;
NScaleRuler rulerY = m_Chart.Axis(m_Series.VerticalAxes[0]).Scale.Ruler;
// current number of accumulated Bezier points
int bpCount = 0;
// accumulated Bezier points
PointF[] bezierPoints = new PointF[4];
NRange1DD xRange = m_Chart.Axis(StandardAxis.PrimaryX).Scale.RulerRange;
NRange1DD yRange = m_Chart.Axis(StandardAxis.PrimaryY).Scale.RulerRange;
NScale2DToViewTransformation transform = new NScale2DToViewTransformation(m_Chart, (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY);
NPointF viewLeftTop = NPointF.Empty;
NPointF viewRightBottom = NPointF.Empty;
transform.Transform(new NVector2DD(xRange.Begin, yRange.Begin), ref viewLeftTop);
transform.Transform(new NVector2DD(xRange.End, yRange.End), ref viewRightBottom);
NRectangleF clipRect = new NRectangleF(viewLeftTop.X, viewLeftTop.Y, viewRightBottom.X - viewLeftTop.X, viewRightBottom.Y - viewLeftTop.Y);
clipRect.Normalize();
using (Region clipRegion = new Region(clipRect.ToRectangleF()))
{
Region oldCilp = graphics.DeviceGraphics.Clip;
try
{
graphics.DeviceGraphics.Clip = clipRegion;
for (int i = 0; i < Points.Length; i++)
{
// Transform values to chart model coorinates
vecModel.X = rulerX.LogicalToScale(Points[i].X);
vecModel.Y = rulerY.LogicalToScale(Points[i].Y);
// Transform model coordinates to view coordinates
m_Chart.TransformModelToClient(context, vecModel, ref vecView);
// Draw the current point
bool isControlPoint = (i % 3) != 0;
if (isControlPoint)
{
NRectangleF rect = new NRectangleF(vecView.X - 3, vecView.Y - 3, 6, 6);
graphics.PaintEllipse(ControlPointFill, null, rect);
}
else
{
NRectangleF rect = new NRectangleF(vecView.X - 5, vecView.Y - 5, 10, 10);
graphics.PaintEllipse(PointFill, null, rect);
}
// Accumulate Bezier point
bezierPoints[bpCount] = new PointF(vecView.X, vecView.Y);
bpCount++;
if (bpCount == 4)
{
// Draw tangents
graphics.DrawLine(TangentStroke, new NPointF(bezierPoints[0]), new NPointF(bezierPoints[1]));
graphics.DrawLine(TangentStroke, new NPointF(bezierPoints[2]), new NPointF(bezierPoints[3]));
// Draw Bezier line
GraphicsPath path = new GraphicsPath();
path.AddBezier(bezierPoints[0], bezierPoints[1], bezierPoints[2], bezierPoints[3]);
graphics.PaintPath(null, BezierStroke, path);
path.Dispose();
// Update accumultaed points
bezierPoints[0] = bezierPoints[3];
bpCount = 1;
}
}
}
finally
{
graphics.DeviceGraphics.Clip = oldCilp;
}
}
}
The relevant code is:
NRange1DD xRange = m_Chart.Axis(StandardAxis.PrimaryX).Scale.RulerRange;
NRange1DD yRange = m_Chart.Axis(StandardAxis.PrimaryY).Scale.RulerRange;
NScale2DToViewTransformation transform = new NScale2DToViewTransformation(m_Chart, (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY);
NPointF viewLeftTop = NPointF.Empty;
NPointF viewRightBottom = NPointF.Empty;
transform.Transform(new NVector2DD(xRange.Begin, yRange.Begin), ref viewLeftTop);
transform.Transform(new NVector2DD(xRange.End, yRange.End), ref viewRightBottom);
NRectangleF clipRect = new NRectangleF(viewLeftTop.X, viewLeftTop.Y, viewRightBottom.X - viewLeftTop.X, viewRightBottom.Y - viewLeftTop.Y);
clipRect.Normalize();
using (Region clipRegion = new Region(clipRect.ToRectangleF()))
{
Region oldCilp = graphics.DeviceGraphics.Clip;
try
{
graphics.DeviceGraphics.Clip = clipRegion;
// Painting goes here
}
finally
{
graphics.DeviceGraphics.Clip = oldCilp;
}
}
Hope this helps - let us know if you have any questions or meet any problems.
Best Regards,
Nevron Support Team