Page 1 of 1

Set initial values for ScrollPager where?

Posted: Thu Mar 02, 2017 9:03 pm
by 15048900
Hello,

I have been trying to put up the ScrollPager tool, get the user input, close the ScrollPager, add again the ScrollPager but have it set to what it was set to previously.

I cannot find the values to set in order to position the ColorBandTool in the previous location.

Here is the small piece of code that I have been using in order to try this out.

In the designer add one chart and one button:

Code: Select all

using Steema.TeeChart;
using Steema.TeeChart.Styles;
using Steema.TeeChart.Tools;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace ScrollPagerTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        ScrollPager tool;
        Steema.TeeChart.Styles.Line series;

        private void InitializeChart()
        {
            tChart1.Header.Text = "Scroll Pager Tool";
            tChart1.Series.Add(series = new Steema.TeeChart.Styles.Line());
            series.FillSampleValues(1000);
            series.Legend.Visible = false;
        }

        private void AddPagerTool()
        {
            if (tool != null)
            {
                Debug.Print("StartValue before destruction = " + tool.StartValue);
                Debug.Print("EndValue before destruction = " + tool.EndValue);
            }

            Debug.Print("MinimumValue before adding PagerTool = " + tChart1.Axes.Bottom.Minimum);
            Debug.Print("MaximumValue before adding PagerTool = " + tChart1.Axes.Bottom.Maximum);

            tChart1.Tools.Clear();
            double StartValue = tChart1.Axes.Bottom.Minimum;
            double EndValue = tChart1.Axes.Bottom.Maximum;
            tChart1.Tools.Add(tool = new ScrollPager());
            tool.Series = series;

            tool.SubChartTChart.Panel.Pen.Visible = false;
            tool.SubChartTChart.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None;
            tool.SubChartTChart.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;

            Debug.Print("StartValue after creation = " + tool.StartValue);
            Debug.Print("EndValue after creation = " + tool.EndValue);
            tool.StartValue = StartValue;
            tool.EndValue = EndValue;
#if false
            tool.ColorBandTool.Start = StartValue;
            tool.ColorBandTool.End = EndValue;
            tool.GetHorizAxis.Minimum = StartValue;
            tool.GetHorizAxis.Maximum = EndValue;
#endif
            Debug.Print("StartValue after setting from value originally in chart = " + tool.StartValue);
            Debug.Print("EndValue after setting from value originally in chart = " + tool.EndValue);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AddPagerTool();
        }
    }
}
So, how do I do this?

Re: Set initial values for ScrollPager where?

Posted: Fri Mar 03, 2017 9:49 am
by Christopher
Hello,
biqpaulson wrote: So, how do I do this?
You can do this by calling the tChart1.Draw() method which will initialize all chart value, some of which depend on the Chart being completely rendered. The following code works as expected here:

Code: Select all

		private void AddPagerTool()
		{
			if (tool != null)
			{
				Debug.Print("StartValue before destruction = " + tool.StartValue);
				Debug.Print("EndValue before destruction = " + tool.EndValue);
			}

			Debug.Print("MinimumValue before adding PagerTool = " + tChart1.Axes.Bottom.Minimum);
			Debug.Print("MaximumValue before adding PagerTool = " + tChart1.Axes.Bottom.Maximum);

			tChart1.Tools.Clear();
			double StartValue = tChart1.Axes.Bottom.Minimum;
			double EndValue = tChart1.Axes.Bottom.Maximum;
			tChart1.Tools.Add(tool = new ScrollPager());
			tool.Series = series;

			tool.SubChartTChart.Panel.Pen.Visible = false;
			tool.SubChartTChart.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None;
			tool.SubChartTChart.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;

			Debug.Print("StartValue after creation = " + tool.StartValue);
			Debug.Print("EndValue after creation = " + tool.EndValue);

			tChart1.Draw(); //Draw the chart to initialize all values
			tool.StartValue = StartValue;
			tool.EndValue = EndValue;
#if false
            tool.ColorBandTool.Start = StartValue;
            tool.ColorBandTool.End = EndValue;
            tool.GetHorizAxis.Minimum = StartValue;
            tool.GetHorizAxis.Maximum = EndValue;
#endif
			Debug.Print("StartValue after setting from value originally in chart = " + tool.StartValue);
			Debug.Print("EndValue after setting from value originally in chart = " + tool.EndValue);
		}

Re: Set initial values for ScrollPager where?

Posted: Fri Mar 03, 2017 1:34 pm
by 15048900
Works great! Thanks!

Re: Set initial values for ScrollPager where?

Posted: Sat Mar 04, 2017 3:02 am
by 15048900
I think i spoke too soon.

If I use a Sphere style and a Points series the line you gave me crashes.

Code: Select all

//#define USE_POINTER_STYLE_SPHERE
using Steema.TeeChart;
using Steema.TeeChart.Styles;
using Steema.TeeChart.Tools;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ScrollPagerTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        ScrollPager tool;
        Steema.TeeChart.Styles.Points series;

        private void InitializeChart()
        {
            tChart1.Header.Text = "Scroll Pager Tool";
            tChart1.Series.Add(series = new Steema.TeeChart.Styles.Points());
            series.FillSampleValues(100);
#if (USE_POINTER_STYLE_SPHERE)
            series.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.Sphere;
#endif
        }

        private void AddPagerTool()
        {
            tChart1.Tools.Clear();
            double StartValue = tChart1.Axes.Bottom.Minimum;
            double EndValue = tChart1.Axes.Bottom.Maximum;
            tChart1.Tools.Add(tool = new ScrollPager());
            tool.Series = series;

            tool.SubChartTChart.Panel.Pen.Visible = false;
            tool.SubChartTChart.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None;
            tool.SubChartTChart.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;

            tChart1.Draw(); //Draw the chart to initialize all values

            if ((StartValue != tChart1.Axes.Bottom.MinXValue)
                ||
                (EndValue != tChart1.Axes.Bottom.MaxXValue))
            {
                tool.StartValue = StartValue;
                tool.EndValue = EndValue;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AddPagerTool();
        }
    }
}
Run the code above and it works.

Uncomment out the:

Code: Select all

//#define USE_POINTER_STYLE_SPHERE
So it is:

Code: Select all

#define USE_POINTER_STYLE_SPHERE
Run and push the button on the form.

It will crash in tChart1.Draw();

with the exception:

Code: Select all

ex.Message = "Object reference not set to an instance of an object."
And a stack trace of:

Code: Select all

   at Steema.TeeChart.Drawing.Graphics3D.MixClip(Region region)
   at Steema.TeeChart.Drawing.Graphics3D.SphereEnh(Int32 x1, Int32 y1, Int32 x2, Int32 y2)
   at Steema.TeeChart.Styles.SeriesPointer.Draw(Graphics3D g, Boolean is3D, Int32 px, Int32 py, Int32 tmpHoriz, Int32 tmpVert, Color colorValue, PointerStyles aStyle)
   at Steema.TeeChart.Styles.SeriesPointer.Draw(Graphics3D g, Int32 px, Int32 py, Color colorValue, PointerStyles aStyle)
   at Steema.TeeChart.Styles.CustomPoint.DrawPointer(Int32 aX, Int32 aY, Color aColor, Int32 valueIndex)
   at Steema.TeeChart.Styles.CustomPoint.DrawValue(Int32 valueIndex)
   at Steema.TeeChart.Styles.Series.DoDrawIndex(Int32 Index, Boolean CanID)
   at Steema.TeeChart.Styles.Series.Draw()
   at Steema.TeeChart.Styles.Series.DrawSeries()
   at Steema.TeeChart.Chart.DoDraw(Graphics3D g, Int32 First, Int32 Last, Int32 Inc)
   at Steema.TeeChart.Chart.DrawAllSeries(Graphics3D g)
   at Steema.TeeChart.Chart.InternalDraw(Graphics g, Boolean noTools)
   at Steema.TeeChart.Chart.Draw(Graphics g, Rectangle r, Boolean noTools)
   at Steema.TeeChart.Chart.Draw(Graphics g, Rectangle r)
   at Steema.TeeChart.Chart.Draw()
   at ScrollPagerTest.Form1.AddPagerTool() in C:\Users\Gary\Documents\Visual Studio 2015\Projects\ScrollPagerTest\ScrollPagerTest\Form1.cs:line 118

Re: Set initial values for ScrollPager where?

Posted: Mon Mar 06, 2017 10:12 am
by Christopher
biqpaulson wrote: If I use a Sphere style and a Points series the line you gave me crashes.
I have been able to confirm this unhandled exception and have already fixed it. Many apologies for the inconvenience. In the meantime you can use the following code to workaround the issue:

Code: Select all

    ScrollPager tool;
    Steema.TeeChart.Styles.Points series;

    private void InitializeChart()
    {
      tChart1.Header.Text = "Scroll Pager Tool";
      tChart1.Series.Add(series = new Steema.TeeChart.Styles.Points());
      series.FillSampleValues(100);
      series.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.Sphere;
    }

    private void AddPagerTool()
    {
      tChart1.Tools.Clear();
      double StartValue = 5;
      double EndValue = 25;
      tChart1.Tools.Add(tool = new ScrollPager());
      series.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.Rectangle;
      tool.Series = series;

      tool.SubChartTChart.Panel.Pen.Visible = false;
      tool.SubChartTChart.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None;
      tool.SubChartTChart.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;

      tChart1.Draw(); //Draw the chart to initialize all values

      tool.SubChartTChart.Series.RemoveAllSeries();
      series.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.Sphere;
      tool.Series = series;

      if ((StartValue != tChart1.Axes.Bottom.MinXValue)
          ||
          (EndValue != tChart1.Axes.Bottom.MaxXValue))
      {
        tool.StartValue = StartValue;
        tool.EndValue = EndValue;
      }
    }

    private void button1_Click(object sender, EventArgs e)
    {
      AddPagerTool();
    }