. You can find below a sample code snippet demonstrating how to achieve the illustrated behavior:
public
RadForm1()
{
InitializeComponent();
this
.radChartView1.CreateRenderer += radChartView1_CreateRenderer;
ScatterLineSeries scatterSeries =
new
ScatterLineSeries();
scatterSeries.DataPoints.Add(
new
ScatterDataPoint(15, 19));
scatterSeries.DataPoints.Add(
new
ScatterDataPoint(18, 10));
scatterSeries.DataPoints.Add(
new
ScatterDataPoint(13, 15));
scatterSeries.DataPoints.Add(
new
ScatterDataPoint(10, 8));
scatterSeries.DataPoints.Add(
new
ScatterDataPoint(5, 2));
scatterSeries.PointSize =
new
SizeF(8, 8);
this
.radChartView1.Series.Add(scatterSeries);
ScatterLineSeries scatterSeries2 =
new
ScatterLineSeries();
scatterSeries2.DataPoints.Add(
new
ScatterDataPoint(2, 24));
scatterSeries2.DataPoints.Add(
new
ScatterDataPoint(7, 12));
scatterSeries2.DataPoints.Add(
new
ScatterDataPoint(15, 10));
scatterSeries2.DataPoints.Add(
new
ScatterDataPoint(18, 22));
scatterSeries2.DataPoints.Add(
new
ScatterDataPoint(20, 20));
scatterSeries2.Shape =
new
RoundRectShape(1);
scatterSeries2.PointSize =
new
SizeF(8, 8);
this
.radChartView1.Series.Add(scatterSeries2);
CartesianGridLineAnnotation annotation1 =
new
CartesianGridLineAnnotation();
annotation1.Axis =
this
.radChartView1.Axes[0]
as
CartesianAxis;
annotation1.Value = 5.8;
annotation1.Label =
"Some text"
;
annotation1.BorderColor = Color.Red;
annotation1.BorderDashStyle = DashStyle.Solid;
annotation1.BorderWidth = 1;
this
.radChartView1.Annotations.Add(annotation1);
}
private
void
radChartView1_CreateRenderer(
object
sender, ChartViewCreateRendererEventArgs e)
{
e.Renderer =
new
CustomRenderer(e.Area
as
CartesianArea);
}
public
class
CustomRenderer : CartesianRenderer
{
public
CustomRenderer(CartesianArea area) :
base
(area)
{
}
protected
override
void
InitializeAnnotations(AnnotationDrawMode drawMode)
{
for
(
int
i = 0; i <
this
.Area.Annotations.Count; i++)
{
if
(
this
.Area.Annotations[i]
is
CartesianGridLineAnnotation)
{
this
.DrawParts.Add(
new
CustomCartesianGridLineAnnotationDrawPart(
this
.Area.Annotations[i]
as
CartesianGridLineAnnotation,
this
));
}
}
}
}
public
class
CustomCartesianGridLineAnnotationDrawPart : CartesianGridLineAnnotationDrawPart
{
public
CustomCartesianGridLineAnnotationDrawPart(CartesianGridLineAnnotation element, CartesianRenderer renderer) :
base
(element, renderer)
{
}
public
override
void
Draw()
{
FieldInfo fi =
typeof
(CartesianGridLineAnnotation).GetField(
"model"
, BindingFlags.Instance | BindingFlags.NonPublic);
ChartAnnotationModel model = fi.GetValue(
this
.Element)
as
ChartAnnotationModel;
RectangleF rect = ChartRenderer.ToRectangleF(model.LayoutSlot);
rect.Offset(
this
.ViewportOffsetX,
this
.ViewportOffsetY);
Graphics graphics =
this
.Renderer.Surface
as
Graphics;
RadGdiGraphics radGraphics =
new
RadGdiGraphics(graphics);
Rectangle clipRect = ChartRenderer.ToRectangle(
this
.Element.View.GetArea<CartesianArea>().AreaModel.PlotArea.LayoutSlot);
clipRect.Offset((
int
)
this
.ViewportOffsetX, (
int
)
this
.ViewportOffsetY);
graphics.SetClip(clipRect);
GraphicsPath path =
new
GraphicsPath();
path.AddLine(rect.Location,
new
PointF(rect.Right, rect.Bottom));
BorderPrimitiveImpl border =
new
BorderPrimitiveImpl(
this
.Element,
null
);
border.PaintBorder(radGraphics,
null
, path, rect);
rect.Size = graphics.MeasureString(
this
.Element.Label,
this
.Element.Font);
rect.Offset(
this
.Element.PositonOffset.Width + 1,
this
.Element.PositonOffset.Height + 1);
TextParams tp =
new
TextParams();
tp.textOrientation = Orientation.Vertical;
tp.font =
this
.Element.Font;
tp.foreColor =
this
.Element.ForeColor;
tp.paintingRectangle =
new
RectangleF(rect.X, rect.Y, rect.Height, rect.Width);
tp.text =
this
.Element.Label;
FillPrimitiveImpl fill =
new
FillPrimitiveImpl(
this
.Element,
null
);
fill.PaintFill(radGraphics,
null
, rect);
radGraphics.DrawString(tp,
new
SizeF(rect.Height, rect.Width));
}
}
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Dess | Tech Support Engineer, Sr.