ScrollPager doesn't respect the margin of customaxis

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: ScrollPager doesn't respect the margin of customaxis

Post by Christopher » Thu May 22, 2014 1:08 pm

Hello!
wakeup wrote:Tchart still is having problmes to set well the margin with scrollpager and custom axis. You can reproduce it with the example I sent in the previous post.
Try:

Code: Select all

            private void button2_Click(object sender, EventArgs e)
            {
              tChart1.GetAxesChartRect += tChart1_GetAxesChartRect;
              AddCustomAxis();
            }

            void tChart1_GetAxesChartRect(object sender, Steema.TeeChart.GetAxesChartRectEventArgs e)
            {
              if (tChart1.Series[0].CustomVertAxis != null)
              {
                double maxVal = tChart1.Series[0].YValues.Maximum;
                float twidth = tChart1.Graphics3D.TextWidth(maxVal.ToString(tChart1.Series[0].CustomVertAxis.Labels.ValueFormat));

                int width = Steema.TeeChart.Utils.Round(twidth) + 30;

                Rectangle rect = tChart1.Chart.ChartRect;
                rect.X = width;
                rect.Width = tChart1.Width - 80;
                e.AxesChartRect = rect;
              }
            }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: ScrollPager doesn't respect the margin of customaxis

Post by acastro » Thu May 22, 2014 1:16 pm

It doesn't run the chart and the scrollpager are one over the other...
Attachments
margin2.png
margin2.png (32.22 KiB) Viewed 21006 times

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: ScrollPager doesn't respect the margin of customaxis

Post by Christopher » Thu May 22, 2014 1:44 pm

wakeup wrote:It doesn't run the chart and the scrollpager are one over the other...
Here is your modified project which includes this code, and here is a video of it working correctly with the latest publicly available release of TeeChart.dll.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: ScrollPager doesn't respect the margin of customaxis

Post by acastro » Thu May 22, 2014 1:57 pm

Thanks now it seems to run was confused between GetAxesChartRect functions of the chart and the subcharts...

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: ScrollPager doesn't respect the margin of customaxis

Post by acastro » Thu Jun 19, 2014 12:49 pm

I follow with some problems in the same topic.

Please find an example project to reproduce.
http://193.145.251.126/pnp/files/TnROgF ... leZoom.zip

If you press button1 to configure the chart. Button2 to save the chart, and button 3 to open the save chart the margin in the scrollpager is changed.

And if you reopen the application and press button3 to open the saved chart the margin of the main chart is also changed.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: ScrollPager doesn't respect the margin of customaxis

Post by Narcís » Thu Jun 19, 2014 1:55 pm

Hello wakeup,

That's because when exporting/importing a chart, associated events are not being exported. The reason behind that is that you could load that chart in an application where those events doesn't exist, which would cause an error loading the chart. Having that in mind, you should add the event handlers again. So you should only modify button3_Click code in your project to look like this:

Code: Select all

        private void button3_Click(object sender, EventArgs e)
        {
          chart.Import.Template.Load(@"C:\testzoom.ten");//
          chart.GetAxesChartRect +=chart_GetAxesChartRect;
          Steema.TeeChart.Tools.ScrollPager mt = (Steema.TeeChart.Tools.ScrollPager)chart.Tools[0];
          mt.SubChartTChart.GetAxesChartRect += SubChartTChart_GetAxesChartRect;
          addPagescroller(mt);
        }
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: ScrollPager doesn't respect the margin of customaxis

Post by acastro » Fri Jun 20, 2014 7:14 am

Thanks I understand your point, but anyway, if that events sets some properties to the chart, why that property values are not saved and then loaded when opened?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: ScrollPager doesn't respect the margin of customaxis

Post by Narcís » Fri Jun 20, 2014 9:57 am

Hi wakeup,

Those are properties that are calculated dynamically depending from other chart properties, which are only valid after the chart has been painted. Hence them being set with the event handlers. Those values (axis.posAxis, axis.Labels.position and axis.posTitle in Steema.TeeChart.Chart.ReCalcAxisElements) could probably be serialized, which might be good for your particular case, however this wouldn't work importing the .ten file into another chart as the values would need to be recalculated again. Moreover, setting custom AxesChartRect is an advanced chart customisation that it wouldn't be desirable in most importing circumstances and could lead to really unpredictable and weird charts.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: ScrollPager doesn't respect the margin of customaxis

Post by acastro » Fri Jun 20, 2014 10:42 am

Ok thanks. I have another related question.

In order to get the width of the labels we do this?

Code: Select all

                  double maxVal = chart.Series[current].CustomVertAxis.Maximum;

          float twidth = chart.Graphics3D.TextWidth(maxVal.ToString(chart.Series[current].CustomVertAxis.Labels.ValueFormat));
But by example when maxval is 94.33, and the diference between the minimum of the scale and the maximum is big the label doesn’t show decimals, so the label only shows 94. So the twidth is not right because “ValueFormat” says "#,##0.###". But I cannot change the valueformat because it is interesting to show decimals if the scale is short.

How can I know if the scale is showing thee maximum with or without decimals?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: ScrollPager doesn't respect the margin of customaxis

Post by Narcís » Fri Jun 20, 2014 11:27 am

Hi wakeup,

I'm not sure about what you are trying to achieve here.
wakeup wrote:But I cannot change the valueformat because it is interesting to show decimals if the scale is short.
Why not? You can force having decimal values changing "#" to "0" as explained in Custom Numeric Format Strings.
wakeup wrote:How can I know if the scale is showing thee maximum with or without decimals?
You can check it in the GetAxisLabels event, for example:

Code: Select all

        private bool maxHasDecimals = false;
        private double max;

        void chart_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
        {
          if (((Steema.TeeChart.Axis)sender).IsCustom())
          {
            double tmpMax;
            bool tmp = false;

            if (double.TryParse(e.LabelText, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out tmpMax))
            {
              tmp = (tmpMax % Math.Truncate(tmpMax) > 0.0);
            }

            if (tmpMax > max)
            {
              max = tmpMax;
              maxHasDecimals = tmp;
            }
          }
        }
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: ScrollPager doesn't respect the margin of customaxis

Post by acastro » Fri Jun 20, 2014 1:12 pm

Narcís wrote:Hi wakeup,

I'm not sure about what you are trying to achieve here.
wakeup wrote:But I cannot change the valueformat because it is interesting to show decimals if the scale is short.
Why not? You can force having decimal values changing "#" to "0" as explained in Custom Numeric Format Strings.
I can't because if the values by example are between 0 an 1, I like to see the decimals... if they are between 0 and 90 no.
Narcís wrote:
wakeup wrote:How can I know if the scale is showing thee maximum with or without decimals?
You can check it in the GetAxisLabels event, for example:

Code: Select all

        private bool maxHasDecimals = false;
        private double max;

        void chart_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
        {
          if (((Steema.TeeChart.Axis)sender).IsCustom())
          {
            double tmpMax;
            bool tmp = false;

            if (double.TryParse(e.LabelText, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out tmpMax))
            {
              tmp = (tmpMax % Math.Truncate(tmpMax) > 0.0);
            }

            if (tmpMax > max)
            {
              max = tmpMax;
              maxHasDecimals = tmp;
            }
          }
        }
It doesn't run, I tried and I got
maxHasDecimals = true
max = 94.832
but in the labels the maximum value you can see is 90. Without decimals...
Thanks

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: ScrollPager doesn't respect the margin of customaxis

Post by Narcís » Fri Jun 20, 2014 1:36 pm

Hello wakeup,
wakeup wrote: I can't because if the values by example are between 0 an 1, I like to see the decimals... if they are between 0 and 90 no.
Ok, in that case you should manually parse e.LabelText argument in the GetAxisLabel event, for example:

Code: Select all

        void chart_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
        {
          if (((Steema.TeeChart.Axis)sender).IsCustom())
          {
            double tmp = Convert.ToDouble(e.LabelText);
            e.LabelText = (tmp < 1) ? tmp.ToString("#.##"): tmp.ToString("#.00");
          }
        }
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: ScrollPager doesn't respect the margin of customaxis

Post by acastro » Fri Jun 20, 2014 1:58 pm

I think you did't undestand me. When I said " between 0 an 1, I like to see the decimals... if they are between 0 and 90 no." it was only and example, the same is if its between 4 and five.... This behaviour is what teechart does automatically. The labels are right, the question is how to acces to the real labels proglamatically... In your example they were with decimals and the real labels although the real labels weren't with decimals...

Thanks

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: ScrollPager doesn't respect the margin of customaxis

Post by Narcís » Fri Jun 20, 2014 2:36 pm

wakeup wrote:I think you did't undestand me. When I said " between 0 an 1, I like to see the decimals... if they are between 0 and 90 no."
Ok, I think I understood you now. In that case you could add something like the code below at the end of button1_Click method in your project.

Code: Select all

          chart.Draw();

          for (int i = 0; i < chart.Axes.Custom.Count; i++)
          {
            Steema.TeeChart.Axis a = chart.Axes.Custom[i];
            double range = a.Maximum - a.Minimum;

            a.Labels.ValueFormat = (range < 1) ? "#.00" : "#.##";
          }
wakeup wrote: it was only and example, the same is if its between 4 and five.... This behaviour is what teechart does automatically. The labels are right, the question is how to acces to the real labels proglamatically... In your example they were with decimals and the real labels although the real labels weren't with decimals...
Ok. You should get the labels using the GetAxisLabels and GetNextAxisLabel. You'll find more information about those events in tutorial 4, at the "Axis events" section. Tutorials can be found at TeeChart's program group.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: ScrollPager doesn't respect the margin of customaxis

Post by acastro » Fri Jun 20, 2014 2:43 pm

Narcís wrote:
wakeup wrote:I think you did't undestand me. When I said " between 0 an 1, I like to see the decimals... if they are between 0 and 90 no."
Ok, I think I understood you now. In that case you could add something like the code below at the end of button1_Click method in your project.

Code: Select all

          chart.Draw();

          for (int i = 0; i < chart.Axes.Custom.Count; i++)
          {
            Steema.TeeChart.Axis a = chart.Axes.Custom[i];
            double range = a.Maximum - a.Minimum;

            a.Labels.ValueFormat = (range < 1) ? "#.00" : "#.##";
          }
Thanks but I don't need this, this is for changing the lables and the labels are right in my graph automatically. That's not the problem
Narcís wrote:
wakeup wrote: it was only and example, the same is if its between 4 and five.... This behaviour is what teechart does automatically. The labels are right, the question is how to acces to the real labels proglamatically... In your example they were with decimals and the real labels although the real labels weren't with decimals...
Ok. You should get the labels using the GetAxisLabels and GetNextAxisLabel. You'll find more information about those events in tutorial 4, at the "Axis events" section. Tutorials can be found at TeeChart's program group.
I have seen the tutorial, but it is not usefully because e.LabelText and e.LabelValue are not the labels shown in my chart, they are with decimals although the labels in my chart are without decimals.

Post Reply