Profile Picture

Arrow

Posted By ANDRE SIMOES 13 Years Ago
Author
Message
ANDRE SIMOES
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 9, Visits: 1
Hi, there is any way to easily put an arrow on the end of a line? Im trying to draw custom axes inside my graphic using lines. There is any way to put an arrow on the end?

m_Line2 = (NLineSeries)m_Chart.Series.Add(SeriesType.Line);
m_Line2.Name = "Alimentador";
m_Line2.InflateMargins = true;
m_Line2.DataLabelStyle.Visible = true;

m_Line2.MarkerStyle.Visible = false;
m_Line2.SamplingMode = SeriesSamplingMode.Enabled;
m_Line2.LineSize = new NLength(50);
m_Line2.MarkerStyle.PointShape = PointShape.Cylinder;
m_Line2.MarkerStyle.Width = new NLength(1.5f, NRelativeUnit.ParentPercentage);
m_Line2.MarkerStyle.Height = new NLength(1.5f, NRelativeUnit.ParentPercentage);
m_Line2.UseXValues = true;
m_Line2.Values.Add(0);
m_Line2.XValues.Add(-125);
m_Line2.Values.Add(0);
m_Line2.XValues.Add(20);
m_Line2.BorderStyle.Color = Color.Black;

I thought this m_Line2.MarkerStyle.PointShape = PointShape.Cylinder should do something like this


Thanks

Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Andre,

This can be achieved with custom painting - the following example shows how to add a line cap at the end of the line:

  public class CustomPaintCallback : NPaintCallback
  {
   public CustomPaintCallback(NChartControl chartControl, NChart chart, NLineSeries line)
   {
    m_Line = line;
    m_Chart = chart;
    m_ChartControl = chartControl;
   }

   public override void OnAfterPaint(NPanel panel, NPanelPaintEventArgs eventArgs)
   {
    NScale2DToViewTransformation scale2View = new NScale2DToViewTransformation(m_ChartControl.View.Context, m_Chart, (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY);

    int count = m_Line.Values.Count;
    if (count < 2)
    {
     return;
    }

    double y1 = (double)m_Line.Values[count - 2];
    double x1 = (double)m_Line.XValues[count - 2];

    double y2 = (double)m_Line.Values[count - 1];
    double x2 = (double)m_Line.XValues[count - 1];

    NPointF point1 = new NPointF();
    NPointF point2 = new NPointF();
    scale2View.Transform(new NVector2DD(x1, y1), ref point1);
    scale2View.Transform(new NVector2DD(x2, y2), ref point2);

    // now paint the arrow
    Graphics graphics = eventArgs.Graphics.DeviceGraphics;
    GraphicsState state = graphics.Save();

    double angle = Math.Atan2(point1.Y - point2.Y, point1.X - point2.X);
    graphics.TranslateTransform(point2.X, point2.Y);

    double rad2Degree = 57.2958f;
    graphics.RotateTransform((float)(rad2Degree * angle) - 90);

    using (SolidBrush brush = new SolidBrush(Color.Black))
    {
     using (GraphicsPath path = new GraphicsPath())
     {
      float arrowSize = 5;
      path.AddLine(new PointF(0, 0), new PointF(-arrowSize, arrowSize));
      path.AddLine(new PointF(-arrowSize, arrowSize), new PointF(arrowSize, arrowSize));
      path.CloseAllFigures();
      graphics.FillPath(brush, path);
     }
    }
    

    graphics.Restore(state);
   }

   NLineSeries m_Line;
   NChart m_Chart;
   NChartControl m_ChartControl;
  }

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

   NLineSeries m_Line2 = (NLineSeries)m_Chart.Series.Add(SeriesType.Line);
   m_Line2.Name = "Alimentador";
   m_Line2.InflateMargins = true;
   m_Line2.DataLabelStyle.Visible = true;

   m_Line2.MarkerStyle.Visible = false;
   m_Line2.SamplingMode = SeriesSamplingMode.Enabled;
   m_Line2.LineSize = new NLength(50);
   m_Line2.MarkerStyle.PointShape = PointShape.Cylinder;
   m_Line2.MarkerStyle.Width = new NLength(1.5f, NRelativeUnit.ParentPercentage);
   m_Line2.MarkerStyle.Height = new NLength(1.5f, NRelativeUnit.ParentPercentage);
   m_Line2.UseXValues = true;
   m_Line2.Values.Add(0);
   m_Line2.XValues.Add(-125);
   m_Line2.Values.Add(10);
   m_Line2.XValues.Add(20);
   m_Line2.BorderStyle.Color = Color.Black;

   m_Chart.PaintCallback = new CustomPaintCallback(nChartControl1, m_Chart, m_Line2);
  }

Hope this helps - let us know if you meet any problems...



Best Regards,
Nevron Support Team



ANDRE SIMOES
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 9, Visits: 1
Fantastic!! Worked perfectly.

I have one more last question to finish my customized 2D graphic.

On my attachment I made an red line using Paint and I wanted to do this on my graphic. Can you tell me where on Nevron Samples I can find a example to draw an Arc? Like giving 2 points and a angle to draw it.

The theta labels im sure I can find how to do it, I have just this arc drawing question.

Thank you, the nevron support is amazing!



Attachments
b.png (70 views, 155.00 KB)
Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Andre,

You can in fact draw anything that's supported by GDI+ - there is no dedicated example for drawing ars, however the GraphicsPath has a method called AddArc which you can use for this purpose. Following is the link in MSDN:

http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.graphicspath.addarc.aspx

Hope this helps - let us know if you meet any problems.



Best Regards,
Nevron Support Team



ANDRE SIMOES
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 9, Visits: 1
Hi,

GraphicPath.AddArc function is define as "add arc to current figure". I used, but nothing happend. But I was expecting it, because I didnt make any association with my NChartControl. How can I make this association?

Thanks,

Andre

Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Andre,

How did you call this function? In general the GDI+ api it is out of the scope of the forum...



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic