Menu

Setting horizontal scrollbar to stat

Help
2007-01-19
2012-09-19
  • commander_keen

    commander_keen - 2007-01-19

    Hello,

    I'm having a problem with zedgraphs auto-scaling.
    It behaves kinda strange: when I set XAxis.Scale.MaxAuto = true and the scrollbar is not at the initial position (left-most), the scrollbar remains active and is scrolled to the right-most position. Scaling is performed in the correct "direction" but i doesn't fit.
    And when setting XAxis.Scale.Max = 100 (having more than 100 values to display of course) the graph disappears completely and the scrollbar-thingy becomes veeery small) Is this a bug?
    This does not happen if I do XAxis.Scale.MaxAuto = true when the scrollbar is at it's left-most position. I can switch between auto-scaling and the manual one just fine then. I can even use the scrollbar and put it back to it's initial position manually and everything is fine then.

    As a workaround I decided to set the scrollbar to it's beginning when the view is changed by my chkbSwitchGraph-checkbox right as the fist action before auto-scaling is called.
    I'm wondering on how to set the h-scrollbar back to the beginning? I was trying to set HorizontalScroll.Value = 0 but it does not seem to have any effect at all..

        private void chkbSwitchGraph_CheckedChanged(object sender, EventArgs e)
        {
            GraphPane myPane = zedGraphControl1.GraphPane;
            if (chkbSwitchGraph.Checked) 
            {
                zedGraphControl1.HorizontalScroll.Value = 0;
                myPane.XAxis.Scale.MaxAuto = true; 
            }
            else
                myPane.XAxis.Scale.Max = 100;
            zedGraphControl1.AxisChange();
            //zedGraphControl1.Invalidate();
        }
    

    Did I get that property wrong?
    As mentioned here http://sourceforge.net/forum/forum.php?thread_id=1654117&forum_id=392231 I'm unable to view the help for this property neither in the offline-help nor in the online documentation.
    regards

    Martin

     
    • John Champion

      John Champion - 2007-02-19

      Hi,
      The HorizontalScroll property is the scrollbar that is associated with the user control (e.g., it would scroll the whole control content including titles, axes, etc., not just the chart area). In your case, you really need to just change the min and max properties of the scale and don't mess with the scrollbar settings (they are handled automatically). Here's an example:

      // Basic curve test - Linear Axis
      private void CreateGraph_BasicLinearScroll( ZedGraphControl z1 )
      {
      GraphPane myPane = z1.GraphPane;
      PointPairList list = new PointPairList();

      for ( int i = 1; i < 50; i++ )
      {
      double x = i;
      double y = Math.Sin( i / 8.0 ) * 100 + 101;
      list.Add( x, y );
      }

      LineItem myCurve = myPane.AddCurve( "curve", list, Color.Blue, SymbolType.Diamond );
      myCurve.Line.Fill = new Fill( Color.Red, Color.White );

      // Show the horizontal scrollbar
      z1.IsShowHScrollBar = true;
      // Tell ZedGraph to automatically set the range of the scrollbar according to the data range
      z1.IsAutoScrollRange = true;
      // Make the scroll cover slightly more than the range of the data
      // (This is a brand new property in the development version -- leave this line out if you are using an older one).
      z1.ScrollGrace = .05;

      // Set the initial x range manually
      z1.GraphPane.XAxis.Scale.Min = 20;
      z1.GraphPane.XAxis.Scale.Max = 30;

      z1.AxisChange();
      }

      If you want to later programatically scroll the graph, you can do it like this:

      // Scroll the graph to x=10, keeping the same span of data
      Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;
      double range = xScale.Max - xScale.Min;
      xScale.Min = 10;
      xScale.Max = 10 + range;
      Refresh();

      John

       
    • commander_keen

      commander_keen - 2007-02-19

      argh HorizontalScroll is read-only of course, only "get" is allowed.

      the problem can be worked around by setting the Scale.Min(Auto) too, not only the Scale.Max(Auto)

          private void chkbSwitchGraph_CheckedChanged(object sender, EventArgs e)
          {
              GraphPane myPane = zedGraphControl1.GraphPane;
              if (chkbSwitchGraph.Checked)
              {
                  myPane.XAxis.Scale.MaxAuto = true;
                  myPane.XAxis.Scale.MinAuto = true;
              }
              else
              {
                  myPane.XAxis.Scale.Min = 0;
                  myPane.XAxis.Scale.Max = 150;
              }
              zedGraphControl1.AxisChange();
              zedGraphControl1.Invalidate();
          }
      

      Still it would be interesting on how to programatically set the value of the scrollbar of the zedgraph...

       

Log in to post a comment.