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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:01:56+00:00 2026-05-26T15:01:56+00:00

I have a zedgraph control where I got at the the basic line chart

  • 0

I have a zedgraph control where I got at the the basic line chart of sine and cosine wave (from tutorial)

I am trying to add a BoxObj to the curve by clicking on it (code below) and I see that the BoxObj is added to GraphObjList, but nothing is actually drawn. Can it be the location that I give the object?

     //This works
     void zedGraphControl1_Click(object sender, EventArgs e)
        {
            Point p = (e as MouseEventArgs).Location;
            CurveItem nearestCurve;
            int index;

            this.zedGraphControl1.GraphPane.FindNearestPoint(new PointF(p.X, p.Y), out nearestCurve, out index);
            //Check for null when no curve clicked
            if (nearestCurve == null)
                return;

            BoxObj box = new BoxObj(nearestCurve[index].X, nearestCurve[index].Y, 1, 0.1, Color.Black,Color.Red);
            box.IsVisible = true;
            box.Location.CoordinateFrame = CoordType.AxisXYScale;

            box.ZOrder = ZOrder.A_InFront;
            zedGraphControl1.GraphPane.GraphObjList.Add(box);


            zedGraphControl1.Invalidate();
        }

Here is the whole graph creation

public void CreateGraph(zedGraph ZedGraphControl)
{
    // Lets generate sine and cosine wave
    double[] x = new double[100];
    double[] y = new double[100];
    double[] z = new double[100];

    for (int i = 0; i < x.Length; i++)
    {
        x[i] = i;
        y[i] = Math.Sin(0.3 * x[i]);
        z[i] = Math.Cos(0.3 * x[i]);
    }

    // This is to remove all plots
    zedGraph.GraphPane.CurveList.Clear();

    // GraphPane object holds one or more Curve objects (or plots)
    GraphPane myPane = zedGraph.GraphPane;

    // PointPairList holds the data for plotting, X and Y arrays 
    PointPairList spl1 = new PointPairList(x, y);
    PointPairList spl2 = new PointPairList(x, z);

    // Add cruves to myPane object
    LineItem myCurve1 = myPane.AddCurve("Sine Wave", spl1, Color.Blue, SymbolType.None);
    LineItem myCurve2 = myPane.AddCurve("Cosine Wave", spl2, Color.Red, SymbolType.None);

    myCurve1.Line.Width = 3.0F;
    myCurve2.Line.Width = 3.0F;
    myPane.Title.Text = "My First Plot";

    // I add all three functions just to be sure it refeshes the plot.   
    zedGraph.AxisChange();
    zedGraph.Invalidate();
    zedGraph.Refresh();
}

Environment:
MS Visual Studio 2010 and .NET Framework 4.0 on Windows XP

  • 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-05-26T15:01:57+00:00Added an answer on May 26, 2026 at 3:01 pm

    You’re right, the location is wrong. The click-Event gives you the display-coordinates, but the BoxObj Constructor needs either units of your axis-scales or fraction of the chart-rect, depending on the CoordType of your BoxObj.
    So you have to decide, which CoordType is more handy to you, convert the event-location to this type and also assign the CoordType to your BoxObj, for instance:

    box.Location.CoordinateFrame = CoordType.XScaleYChartFraction;
    

    EDIT: For testing you could try the following, and the box should be in the middle of your chart:

    BoxObj box = new BoxObj(0.5, 0.5, 40, 40, Color.Black,Color.Red);
    box.Location.CoordinateFrame = CoordType.ChartFraction;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a sine curve in ZedGraph that goes from -10 to
I got a histogram drawn in ZedGraph. And I have to set the specific
I have bit of code that draws nice line charts in ZedGraph . I
Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the
In Zedgraph (asp.net) I have a datapoint list where the x values are of
I have a program that adds LineItems to a ZedGraph pane whenever data parameters
Have a LinqtoSql query that I now want to precompile. var unorderedc = from
Have been trying the whole day long and googled the **** out of the
Have a photography site that I want to prevent image copying from. How can
Have have this line of code in my form when I create a new

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.