SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

Answered
0
0

Hi,
I have the necessity to allow the user to draw one or several polygons upon a heatmap chart to let him select the region he is interested in. See attached image.

I don’t want to selected the markers inside the drawn polygon, only to know the coordinates (in data coordinates, not screen) of the various point that define the polygon.
I saw that the way to do this is to use Annotations however it’s not clear to me if is it possible to have the same behaviour of the BoxAnnotation but with a polygon (without any side number limit)?

Thank you,

Raphael

Version
4.2.2
Images
  • You must to post comments
Great Answer
0
0

Hi Raphael,

Two ways to achieve this. In our SciChart WPF Examples we have published a modifier which allows the user to free-draw over the chart:

  1. Github repository here:
  2. The Free draw modifier is here

This results in the following

enter image description here

In addition to this, if you just wanted to draw from programmatic data, you can use our CustomRenderableSeries API?

In essence, you can override one of our series (or create your own), and draw directly to the screen using the Immediate Mode RenderContext API. Using this technique you can draw pretty much anything on the chart.

I would suggest inheriting FastHeatmapRenderableSeries and calling the base Draw method before drawing your own polygon.

e.g.

public class HeatmapSeriesEx : FastHeatMapRenderableSeries
{
    protected override void InternalDraw(IRenderContext2D renderContext, IRenderPassData renderPassData)
    {
        // Draws the base heatmap 
        base.InternalDraw(renderContext, renderPassData);

        // Draw whatever you want over the top! 

        // Filling polygon
        using (var brush = renderContext.CreateBrush(Color.FromArgb(0x33, 0xFF, 0x33, 0x33)))
        {
            IEnumerable<Point> points; // define your points
            renderContext.FillPolygon(brush, points);
        }

        // Drawing lines (polygon ouline)
        using (var pen = renderContext.CreatePen(Colors.Red, true, 2.0f))
        using (var lineContext = renderContext.BeginLine(pen, 10d, 10d))
        {
            lineContext.MoveTo(20, 20);
            lineContext.MoveTo(50, 100);
            lineContext.MoveTo(20, 120);
            lineContext.MoveTo(10d, 10d);
            lineContext.End();
        }
    }
}

Will allow you to draw a filled and outlined polygon over the chart from programmatic points.

Hope this helps!

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.