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 8691759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:11:15+00:00 2026-06-13T00:11:15+00:00

Using a chart control on a windows form in C#, with visual studio 2010

  • 0

Using a chart control on a windows form in C#, with visual studio 2010 IDE.

I’m creating a chart that plots random points. Once points are generated, I run a loop for each point in the chart, looking at all the other point coordinates. Inside that loop, I calculate the distance from the parent point to it’s neighbor. If the distance is <= some distance that I specify, I want a line to be drawn showing a connection between the two. Problem I’m having though is actually drawing that line. Further more, I then need to find a way to walk the shortest path in that chart.

So this is really two questions:
1. How do I draw the lines on the chart? (current dilemma)
2. How do I walk the graph to find the shortest path?

Here is a snipper of some code I’m using to accomplish this, along with the current error:

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["Series1"].Points.AddXY
                        (rdn.Next(x), rdn.Next(y));
        }

        for (int i = 0; i <= dgNodes - 1; i++)
        {
            chtGraph.Series["Series2"].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)
    {

        Pen pen = new Pen(Color.Black, 1);
        Graphics g = chtGraph.CreateGraphics();

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

        //Gather all the data generator data points into a point array
        foreach (DataPoint p in chtGraph.Series[0].Points)
        {
            Point point = new Point((int)p.XValue, (int)p.YValues[0]);
            pts[i] = point;
            i++;
        }

        //Gather all the non data generator into the same point array
        foreach (DataPoint p in chtGraph.Series[1].Points)
        {
            Point point = new Point((int)p.XValue, (int)p.YValues[0]);
            pts[i] = point;
            i++;
        }

        //loop through all the data points
        foreach (Point p in pts)
        {
            //examine all the other data points for each data point visited
            for (int j = 0; j < pts.Length; j++)
            {

                //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.X - pts[j].X), 2) + Math.Pow((p.Y - pts[j].Y), 2)) <= intTransPower)
                {
                    //gr.DrawLine(pen, p, pts[j]);
                    //gr.Graphics.DrawLine(pen, p.X, p.Y, pts[j].X, pts[j].Y);

                }
            }
        }
    }

    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["Series1"].Points.Clear();
        chtGraph.Series["Series2"].Points.Clear();

        buildGraph(intXAxis, intYAxis, intNumNodes, intNum_DG);

        drawEdges(intNumNodes, intTransPower);
    }

}

Error: Error 1 The type ‘System.Windows.Forms.DataVisualization.Charting.ChartGraphics’ has no constructors defined

  • 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-13T00:11:17+00:00Added an answer on June 13, 2026 at 12:11 am

    Used event described in comment in the question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MS chart control .net 4 framework in Visual studio 2010 using
I am currently using the Chart Control from System.Windows.Forms.DataVisualization to dynamically creating 10 chart
I'm creating an Excel chart using C++. My problem is that I want to
I am using a Microsoft Chart control (system.windows.forms.datavisualization.charting.chart) in a Windows forms application, vb.net
I am using the .NET Chart Control library that comes with .NET 4.0 Beta
Using Microsoft's charting control, System.Windows.Forms.DataVisualization.Charting.Chart, I am trying to render a chart to vector
I have a problem with chart export. I´m using MS Chart (System.Windows.Controls.DataVisualization.Toolkit) I can
I am using a chart control to show some data as a Column Chart.
I'm implementing a scatter plot using the MS Chart Control .NET 3.5, WinForms, C#.
Simple question but cannot find answer anywhere. When using a MS Chart Control of

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.