Nevron Forum

Plotting Circle

https://www.nevron.com/Forum/Topic3902.aspx

By Teddy Lambropoulos - Wednesday, July 28, 2010

Is there an easy way to plot a circle? I have tried using an NSmoothLineSeries for this, but the size of the data point markers makes the plot look "choppy." Is there an easier way to do this? Perhaps predefined shapes?

 

Best regards,

 

Teddy

By Nevron Support - Thursday, July 29, 2010

Hi Teddy,

You can use the GraphicsPath flatten method in a combination with a scatter line series to get a "circle"- for example:

private void Form1_Load(object sender, EventArgs e)
{
  NChart chart = nChartControl1.Charts[0];

  NLineSeries line = new NLineSeries();
  line.DataLabelStyle.Visible = false;

  using (GraphicsPath path = new GraphicsPath())
  {
    path.AddEllipse(new Rectangle(-10, -10, 20, 20));
    FillFromPath(line, path);
  }

  chart.Series.Add(line);
  chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NLinearScaleConfigurator();

  nChartControl1.Refresh();
}

private void FillFromPath(NLineSeries line, GraphicsPath path)
{
  path.Flatten(null, 0.01f);
  PointF[] points = path.PathPoints;

  line.UseXValues = true;
  int count = points.Length;

  for (int i = 0; i < count; i++)
  {
    PointF point = points[i];
    line.Values.Add(point.X);
    line.XValues.Add(point.Y);
  }
}

We'll have a new series called path series in Vol2 (early autumn) that will allow you to draw graphics path directly in the control. Note that you may not actually get a circle if the plot proportions are not exactly 1:1.

Questions or comments - please feel free...

By Syrhey Karol' - Tuesday, January 10, 2012

Hi Guys!

Is it possible to draw simple shape like circle or rectangle with kind of 'NPathSeries' for now?
By the way NPath class was created for that goal?

Or I shall use the approach like in the previous post?
By Nevron Support - Friday, January 13, 2012

It is possible to draw custom graphics (with GDI+) in the chart canvas. Please refer to the following examples in our Windows forms demo application:

All Examples > Custom Painting > ...
All Examples > Coordinate Transformations > ...
By Syrhey Karol' - Monday, January 16, 2012

Thank you! It works great!

Best regards,
Zonder