none
Ellipse on Chart control RRS feed

  • Question

  • Not sure if this is the correct forum to post in..could not find one specific to charts.

    I'm struggling to figure out how to create a chart that displays ellipses.  Any help is much appreciated.  Can be in C# or VB.net

    I need to draw an ellipse that may not be exactly circular.. so it needs something like x1-x2 and y1-y2 or even x with width and height.

    This is an example where I've drawn the eclipses within a picture box.  I want to duplicate this with a chart.

    Ellipse+Points


    Marty

    Wednesday, July 26, 2017 10:00 PM

All replies

  • Hi MEFletcher,

    Thank you for posting here.

    If you want to draw ellipse in picture, here is a simple example for your reference.

       protected override void OnPaint(PaintEventArgs e)
            {
                pictureBox1.Refresh();
    
                Graphics g = pictureBox1.CreateGraphics();
                g.DrawEllipse(new Pen(Color.Red, 20), new Rectangle(new Point(pictureBox1.Location.X +50, pictureBox1.Location.Y + 25), new Size(200, 200)));
    
                base.OnPaint(e);
            }

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 27, 2017 11:12 AM
    Moderator
  • Wendy, I already know how to do this with a picture... stated in my description. What I'm wanting to do is plot this with the Chart Control rather than picture box.

    Here are the reasons I want to use Chart rather than picture.
    -The DrawEllipse method is x/y starting at 0,0. Sometimes my values are negative or in the 1,000's. I have to do offsets to get it centered nicely with drawellise.
    -I want tooltips on certain points.
    -The charts automatically scale and have axis values.

    In VB6 I use the ChartDirector package, it handles these kind of charts all day long. Seems .NET needs some improvements in the charting area.

    Thursday, July 27, 2017 4:43 PM
  • Hi MartinEFletcher,

    If you want to create a ellipse, you could change the pictureBox1 to chart1 in my previous reply.

    If you want to check the location, you could use MouseMove event. I make a simple code for your reference.

            private void chart1_MouseMove(object sender, MouseEventArgs e)
            {          
                textBox1.Text = e.Location.X.ToString();
                textBox2.Text = e.Location.Y.ToString();
                chart1.Refresh();
    
                Graphics g = chart1.CreateGraphics();
                g.DrawEllipse(new Pen(Color.Red, 20), new Rectangle(new Point(Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text)), new Size(100, 100)));
    
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                // Data arrays.
                string[] seriesArray = { "Cats", "Dogs" };
                int[] pointsArray = { 1, 2 };
    
                // Set palette.
                this.chart1.Palette = ChartColorPalette.SeaGreen;
    
                // Set title.
                this.chart1.Titles.Add("Pets");
    
                // Add series.
                for (int i = 0; i < seriesArray.Length; i++)
                {
                    // Add series.
                    Series series = this.chart1.Series.Add(seriesArray[i]);
    
                    // Add point.
                    series.Points.Add(pointsArray[i]);
                }
            }

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 1, 2017 8:31 AM
    Moderator
  • Again, not what I'm looking for.  I guess you don't understand the request.

    I want use a chart control to plot x/y points on top of an ellipse, using the same same axis's.  the ellipse would need to be a series in the chart.  there will be two ellipses, with many x/y points plotted to see if they are in or outside the ellipse.

    After much searching, it does not looks like the .Net charts has this option. 

    This is what i want to accomplish.  This was done in vb6 with ChartDirector package.

    Tuesday, August 1, 2017 10:37 AM
  • Hi MartinEFletcher,

    For your question,if you want to create a ellipse to be a series in the chart, the winform chart control could not do that.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 2, 2017 7:21 AM
    Moderator