Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Question about using Zedgraph [modified]

Question about using Zedgraph [modified]

Scheduled Pinned Locked Moved C#
data-structuresquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rafone
    wrote on last edited by
    #1

    If this isn't the right place for this question please let me know. I was playing with one of the samples Multi Y Graph. I added a couple of varibles and execute it 4 different times via mouse click. The first time through all works as expected. The second time through the x and y axis work correctly but the 3rd and 4th do not. Can anyone point me in the right direction. Here is the code I am using...

    public partial class Form1 : Form
    {
    private static int clickCount = 0;
    //
    private LineItem myCurve;
    //
    public Form1()
    {
    InitializeComponent();
    }

        #region Graph Test
    
        // Call this method from the Form\_Load method, passing your ZedGraphControl instance
        public void CreateChart(ZedGraphControl zgc)
        {
    
            // Get a reference to the GraphPane
            GraphPane myPane = zgc.GraphPane;
    
            // Set the titles and axis labels
            myPane.Title.Text = "Demonstration of Multi Y Graph";
            myPane.XAxis.Title.Text = "Time, s";
            myPane.YAxis.Title.Text = "Velocity, m/s";
            myPane.Y2Axis.Title.Text = "Acceleration, m/s2";
    
            // Make up some data points based on the Sine function
            PointPairList vList = new PointPairList();
            PointPairList aList = new PointPairList();
            PointPairList dList = new PointPairList();
            PointPairList eList = new PointPairList();
    
            // Fabricate some data values
            for (int i = 0; i < 30; i++)
            {
                double time = (double)i;
                double acceleration = 2.0;
                double velocity = acceleration \* time;
                double distance = acceleration \* time \* time / 2.0;
                double energy = 100.0 \* velocity \* velocity / 2.0;
                aList.Add(time, acceleration);
                vList.Add(time, velocity);
                eList.Add(time, energy);
                dList.Add(time, distance);
            }
            if (clickCount == 1)
            {
                // Generate a red curve with diamond symbols, and "Velocity" in the legend
                LineItem myCurve = myPane.AddCurve("Velocity",
                   vList, Color.Red, SymbolType.Diamond);
                // Fill the symbols with white
                myCurve.Symbol.Fill = new Fill(Color.White);
                //
                // Make the Y axis scale red
                myPane.YAxis.Sca
    
    N T 2 Replies Last reply
    0
    • R Rafone

      If this isn't the right place for this question please let me know. I was playing with one of the samples Multi Y Graph. I added a couple of varibles and execute it 4 different times via mouse click. The first time through all works as expected. The second time through the x and y axis work correctly but the 3rd and 4th do not. Can anyone point me in the right direction. Here is the code I am using...

      public partial class Form1 : Form
      {
      private static int clickCount = 0;
      //
      private LineItem myCurve;
      //
      public Form1()
      {
      InitializeComponent();
      }

          #region Graph Test
      
          // Call this method from the Form\_Load method, passing your ZedGraphControl instance
          public void CreateChart(ZedGraphControl zgc)
          {
      
              // Get a reference to the GraphPane
              GraphPane myPane = zgc.GraphPane;
      
              // Set the titles and axis labels
              myPane.Title.Text = "Demonstration of Multi Y Graph";
              myPane.XAxis.Title.Text = "Time, s";
              myPane.YAxis.Title.Text = "Velocity, m/s";
              myPane.Y2Axis.Title.Text = "Acceleration, m/s2";
      
              // Make up some data points based on the Sine function
              PointPairList vList = new PointPairList();
              PointPairList aList = new PointPairList();
              PointPairList dList = new PointPairList();
              PointPairList eList = new PointPairList();
      
              // Fabricate some data values
              for (int i = 0; i < 30; i++)
              {
                  double time = (double)i;
                  double acceleration = 2.0;
                  double velocity = acceleration \* time;
                  double distance = acceleration \* time \* time / 2.0;
                  double energy = 100.0 \* velocity \* velocity / 2.0;
                  aList.Add(time, acceleration);
                  vList.Add(time, velocity);
                  eList.Add(time, energy);
                  dList.Add(time, distance);
              }
              if (clickCount == 1)
              {
                  // Generate a red curve with diamond symbols, and "Velocity" in the legend
                  LineItem myCurve = myPane.AddCurve("Velocity",
                     vList, Color.Red, SymbolType.Diamond);
                  // Fill the symbols with white
                  myCurve.Symbol.Fill = new Fill(Color.White);
                  //
                  // Make the Y axis scale red
                  myPane.YAxis.Sca
      
      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Read How to get an answer to your question[^] and with attention to #7. Following these guidelines will get better responses to your questions


      I know the language. I've read a book. - _Madmatt

      R 1 Reply Last reply
      0
      • N Not Active

        Read How to get an answer to your question[^] and with attention to #7. Following these guidelines will get better responses to your questions


        I know the language. I've read a book. - _Madmatt

        R Offline
        R Offline
        Rafone
        wrote on last edited by
        #3

        thanks for the tip Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...

        T 1 Reply Last reply
        0
        • R Rafone

          If this isn't the right place for this question please let me know. I was playing with one of the samples Multi Y Graph. I added a couple of varibles and execute it 4 different times via mouse click. The first time through all works as expected. The second time through the x and y axis work correctly but the 3rd and 4th do not. Can anyone point me in the right direction. Here is the code I am using...

          public partial class Form1 : Form
          {
          private static int clickCount = 0;
          //
          private LineItem myCurve;
          //
          public Form1()
          {
          InitializeComponent();
          }

              #region Graph Test
          
              // Call this method from the Form\_Load method, passing your ZedGraphControl instance
              public void CreateChart(ZedGraphControl zgc)
              {
          
                  // Get a reference to the GraphPane
                  GraphPane myPane = zgc.GraphPane;
          
                  // Set the titles and axis labels
                  myPane.Title.Text = "Demonstration of Multi Y Graph";
                  myPane.XAxis.Title.Text = "Time, s";
                  myPane.YAxis.Title.Text = "Velocity, m/s";
                  myPane.Y2Axis.Title.Text = "Acceleration, m/s2";
          
                  // Make up some data points based on the Sine function
                  PointPairList vList = new PointPairList();
                  PointPairList aList = new PointPairList();
                  PointPairList dList = new PointPairList();
                  PointPairList eList = new PointPairList();
          
                  // Fabricate some data values
                  for (int i = 0; i < 30; i++)
                  {
                      double time = (double)i;
                      double acceleration = 2.0;
                      double velocity = acceleration \* time;
                      double distance = acceleration \* time \* time / 2.0;
                      double energy = 100.0 \* velocity \* velocity / 2.0;
                      aList.Add(time, acceleration);
                      vList.Add(time, velocity);
                      eList.Add(time, energy);
                      dList.Add(time, distance);
                  }
                  if (clickCount == 1)
                  {
                      // Generate a red curve with diamond symbols, and "Velocity" in the legend
                      LineItem myCurve = myPane.AddCurve("Velocity",
                         vList, Color.Red, SymbolType.Diamond);
                      // Fill the symbols with white
                      myCurve.Symbol.Fill = new Fill(Color.White);
                      //
                      // Make the Y axis scale red
                      myPane.YAxis.Sca
          
          T Offline
          T Offline
          Thomas Krojer
          wrote on last edited by
          #4

          Try this in your button click event:

          clickCount++;
          if (clickCount > 4)
          {
          clickCount = 1;
          zgc.GraphPane = new GraphPane();
          }
          CreateChart(zgc);

          some work with the pane size remains ...

          R 1 Reply Last reply
          0
          • T Thomas Krojer

            Try this in your button click event:

            clickCount++;
            if (clickCount > 4)
            {
            clickCount = 1;
            zgc.GraphPane = new GraphPane();
            }
            CreateChart(zgc);

            some work with the pane size remains ...

            R Offline
            R Offline
            Rafone
            wrote on last edited by
            #5

            That did it...Thanks so much for your time rafone Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...

            T 1 Reply Last reply
            0
            • R Rafone

              That did it...Thanks so much for your time rafone Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...

              T Offline
              T Offline
              Thomas Krojer
              wrote on last edited by
              #6

              you´re welcome

              1 Reply Last reply
              0
              • R Rafone

                thanks for the tip Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...

                T Offline
                T Offline
                Thomas Krojer
                wrote on last edited by
                #7

                Did you find the solution for keeping the size of your GraphPane? If not, here is it: You need 2 floats

                private float myHeight = 0;
                private float myWidth = 0;

                and in your CreateChart, right after

                GraphPane myPane = zgc.GraphPane;

                you add:

                if (myHeight == 0)
                {
                myWidth = myPane.Rect.Size.Width;
                myHeight = myPane.Rect.Size.Height;
                }
                else
                {
                if (myPane.Rect.Size.Width < myWidth)
                {
                myPane.Rect = new RectangleF(0, 0, myWidth, myHeight);
                }
                }

                R 1 Reply Last reply
                0
                • T Thomas Krojer

                  Did you find the solution for keeping the size of your GraphPane? If not, here is it: You need 2 floats

                  private float myHeight = 0;
                  private float myWidth = 0;

                  and in your CreateChart, right after

                  GraphPane myPane = zgc.GraphPane;

                  you add:

                  if (myHeight == 0)
                  {
                  myWidth = myPane.Rect.Size.Width;
                  myHeight = myPane.Rect.Size.Height;
                  }
                  else
                  {
                  if (myPane.Rect.Size.Width < myWidth)
                  {
                  myPane.Rect = new RectangleF(0, 0, myWidth, myHeight);
                  }
                  }

                  R Offline
                  R Offline
                  Rafone
                  wrote on last edited by
                  #8

                  Thank you Thomas. I was using a different work around but I like this way better. Thanks again for your time and expertise. rafone

                  Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups