Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8608183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:32:34+00:00 2026-06-12T03:32:34+00:00

I’m trying to create a graph that draws some edges between specific vertices. The

  • 0

I’m trying to create a graph that draws some edges between specific vertices. The idea is that I am creating random vertices, and specifying a “transmit power” integer. The way it works is that if the distance between two nodes is less than or equal to the transmit power, a line will get drawn between them.

I’m using the MSDN chart control to do this. Having problems getting lines drawn though. I keep getting the following error message:

Error   2   Argument 2: cannot convert from 'System.Windows.Forms.DataVisualization.Charting.DataPoint' to 'System.Drawing.Point'   

Been trying to crack this one so figured I’d log on to here and see if anyone else might know what to do here. I can’t find anything regarding how to convert this.

Here is some code example:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    public void createNodes(int x, int y, int Nodes, int dgNodes)
    {
        Random rdn = new Random();

        for (int i = 0; i < (Nodes - dgNodes); i++)
        {
            chtGraph.Series["NoDG"].Points.AddXY
                        (rdn.Next(x), rdn.Next(y));
        }

        for (int i = 0; i <= dgNodes - 1; i++)
        {
            chtGraph.Series["DG"].Points.AddXY
                        (rdn.Next(x), rdn.Next(y));
        }
    }

    public void buildGraph(int x, int y, int Nodes, int dgNodes)
    {
        //set the min/max axis on the chart
        chtGraph.ChartAreas["ChartArea1"].AxisX.Maximum = x;
        chtGraph.ChartAreas["ChartArea1"].AxisX.Minimum = 0;
        chtGraph.ChartAreas["ChartArea1"].AxisY.Maximum = y;
        chtGraph.ChartAreas["ChartArea1"].AxisY.Minimum = 0;
        chtGraph.ChartAreas["ChartArea1"].AxisX.Interval = x / 10;
        chtGraph.ChartAreas["ChartArea1"].AxisY.Interval = y / 10;

        chtGraph.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
        chtGraph.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;

        //build all the nodes
        createNodes(x, y, Nodes, dgNodes);
    }

    public void drawEdges(int intNumNodes, int intTransPower)
    {
        ChartGraphics gr = new ChartGraphics();
        Pen pen = new Pen(Color.Black, 1);
        //System.Drawing.Point[] pts = new Point[4];
        //pts[0] = new Point(20, 20);
        //pts[1] = new Point(20, 140);
        //pts[2] = new Point(60, 60);
        //pts[3] = new Point(180, 80);
        //gr.DrawLine(pen, pts[1], pts[2]);

        DataPoint[] pts = new DataPoint[intNumNodes];
        int i = 0;

        //Gather all the data points into an array
        foreach (DataPoint p in chtGraph.Series[0].Points)
        {
            pts[i] = p;
            i++;
        }

        i = 0;

        //loop through all the data points
        foreach (DataPoint p in pts)
        {
            //examine all the other data points for each data point visited
            for (int j = 0; j < pts.Length; j++)
            {
                //convert the y values
                int yval = Convert.ToInt32(p.YValues[0]);
                int yValNeighbors = Convert.ToInt32(pts[j].YValues[0]);

                //if the distance from the parent node (p) to the neighbor node is less than the transmit power, then draw a line
                if (Math.Sqrt(Math.Pow((p.XValue - pts[j].XValue), 2) + Math.Pow((yval - yValNeighbors), 2)) <= intTransPower)
                {
                    gr.Graphics.DrawLine(pen, p, pts[j);
                }
            }
        }
    }

    private void btnExecute_Click(object sender, EventArgs e)
    {
        if (txtDG.Text == "" || txtNodes.Text == "" || txtStorage.Text == "" || txtTransPower.Text == ""
            || txtXAxis.Text == "" || txtXAxis.Text == "")
        {
            lblError.Text = "Please enter in all inputs!";
            lblError.Visible = true;
            return;
        }
        //create variables for use through program

        int intTransPower = Convert.ToInt32(txtTransPower.Text);
        int intXAxis = Convert.ToInt32(txtXAxis.Text);
        int intYAxis = Convert.ToInt32(txtYAxis.Text);
        int intNum_DG = Convert.ToInt32(txtDG.Text);
        int intNumNodes = Convert.ToInt32(txtNodes.Text);
        int intStorage = Convert.ToInt32(txtStorage.Text);

        lblError.Visible = false;
        lblError.Text = "";

        if (txtDG.Text == "" || txtNodes.Text == "" || txtStorage.Text == "" || txtTransPower.Text == "" 
            || txtXAxis.Text == "" || txtXAxis.Text == "")
        {
            lblError.Text = "Please enter in all inputs!";
            lblError.Visible = true;}

            chtGraph.Series["NoDG"].Points.Clear();
            chtGraph.Series["DG"].Points.Clear();
            buildGraph(intXAxis, intYAxis, intNumNodes, intNum_DG);
            drawEdges(intNumNodes, intTransPower);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:32:35+00:00Added an answer on June 12, 2026 at 3:32 am

    Forgive me if I got this wrong, but DataPoint does not subclass Point. They cant be converted to System.Drawing.Point automatically. Why not create new Points?

    //if the distance from the parent node (p) to the neighbor node is less than the transmit power, then draw 
    if (Math.Sqrt(Math.Pow((p.XValue - pts[j].XValue), 2) + Math.Pow((yval - yValNeighbors), 2)) <= intTransPower)
    {
        var point = new System.Drawing.Point((int)p.XValue, (int)p.YValue); 
        gr.Graphics.DrawLine(pen, point, pts[j);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.