Auto Adjust Axis's Label visible when custom label

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
sim
Newbie
Newbie
Posts: 19
Joined: Wed Jul 30, 2008 12:00 am

Auto Adjust Axis's Label visible when custom label

Post by sim » Mon Jan 16, 2012 7:51 am

I want to realize fellow function using Tchart version:3.5.3225.32185:
when user change the chart window's size,the axis's label can adjust their visible when all labels are custom label.
My Axis's label can't adjust its label's visible when the chart window's size have been changed.The axis's labels will overlap and it is unacceptable!
please look this attachment.
The custom label is added like this:

Code: Select all

  
double x=0;
AxisLabelItem xLabel = tChart1.Axes.Bottom.Labels.Items.Add(Convert.ToDouble(x.ToString("E3")));
                    xLabel.Transparent = true;
                    xLabel.Width = 90;
                    xLabel.Value = x;
for example: the x-axis labels:0.00,1.00,2.00,3.00,4.00,5.00,6.00,7.00,8.00,9.00,10.00.
All label will displayed when max window status,but when user change the chart window's size,there should be only show 0.00,2.00,4.00,6.00,8.00,10.00,The other label should be hidden.
I know the Feature list have realize this function,but my project can't and I don't know what causes this.
I want to know:How can I realize this?Is there have something effective for this or a property can do this?
Attachments
axislabeloverlop.jpg
axis label overlap
axislabeloverlop.jpg (10.39 KiB) Viewed 9499 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Auto Adjust Axis's Label visible when custom label

Post by Sandra » Mon Jan 16, 2012 11:44 am

Hello sim,

I can not reproduce your problem using last version 3 of TeeChart.Net and next code:

Code: Select all

        Steema.TeeChart.Styles.Line line1;
        private void InitializeChart()
        {
            line1 = new Line(tChart1.Chart);
            tChart1.Dock = DockStyle.Fill;
            Random rnd = new Random();
            line1.Add(1.00E3,rnd.Next(100));
            line1.Add(1.10E3,rnd.Next(100));
            line1.Add(2.00E3,rnd.Next(100));
            line1.Add(3.00E3, rnd.Next(100));
            line1.Add(4.00E3, rnd.Next(100));
            line1.Add(5.00E3, rnd.Next(100));
            line1.Add(6.00E3, rnd.Next(100));
            line1.Add(7.00E3, rnd.Next(100));
            line1.Add(8.00E3, rnd.Next(100));
            line1.Add(9.00E3, rnd.Next(100));
            line1.Add(10.00E3, rnd.Next(100));
            tChart1.Axes.Bottom.Labels.ValueFormat = "#.0 x10 E+0";
}
Can you tell us if using next code, your problem appear? If problem doesn't appear, please send us a simple project because we can try to solve your problem here. On the other hand, I have seen that you doesn't have the last maintenace release of TeeChart.Net v3. I recommend you, update your version of TeeChart.Net and check again if your problem persist. You can update your version in costumer page

Thanks,
Best Regards,
Sandra Pazos / 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

sim
Newbie
Newbie
Posts: 19
Joined: Wed Jul 30, 2008 12:00 am

Re: Auto Adjust Axis's Label visible when custom label

Post by sim » Wed Jan 18, 2012 9:47 am

I have upload my project in attachment.your code is not what i mean.this is my code:

Code: Select all

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

namespace teechartScaleOverlapping
{
    public partial class Form1 : Form
    {
        Steema.TeeChart.Styles.Line line1;
        Steema.TeeChart.TChart tChart1;
        public Form1()
        {
            InitializeComponent();
            tChart1 = new Steema.TeeChart.TChart();
            this.panel1.Controls.Add(tChart1);
            line1 = new Line(tChart1.Chart);

            tChart1.Dock = DockStyle.Fill;
            Random rnd = new Random();
            line1.Add(1.00, rnd.Next(100));
            line1.Add(2.00, rnd.Next(100));
            line1.Add(3.00, rnd.Next(100));
            line1.Add(4.00, rnd.Next(100));
            line1.Add(5.00, rnd.Next(100));
            line1.Add(6.00, rnd.Next(100));
            line1.Add(7.00, rnd.Next(100));
            line1.Add(8.00, rnd.Next(100));
            line1.Add(9.00, rnd.Next(100));
            line1.Add(10.00, rnd.Next(100));
         
            tChart1.Axes.Bottom.Labels.Items.Clear();

            for (int i = 0; i < 10; i++)//build 
            {
                double x = i;
                AxisLabelItem xLabel = tChart1.Axes.Bottom.Labels.Items.Add(Convert.ToDouble(x.ToString("E3")));
                xLabel.Width = 90;
                xLabel.Text = x.ToString("E3");
                xLabel.Value = x;
            }
           
        }
    }
}
the above code can reproduce my issues,please help me,thanks!
I have download all version and installed,but I didn't found the last version: 3.5.3700.
In TeeChartNET3UpdateBuild file,there is no Tchart.dll for .net3.5(3.jpg),but my project is .net3.5.Can we user tchart.dll for .net2.0?
I have upload the list version in my customer page(1.jpg),please tell me which file is the last version,thanks?
My project must be use Custom label,reason:http://www.teechart.net/support/viewtop ... =4&t=12864.
Why the custom labels can not auto Adjust Axis's Label visible?
Attachments
3.jpg
3.jpg (34.31 KiB) Viewed 9480 times
1.jpg
please tell me which file is the last version,thanks
1.jpg (57.04 KiB) Viewed 9475 times
teechartScaleOverlapping.zip
(51.99 KiB) Downloaded 883 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Auto Adjust Axis's Label visible when custom label

Post by Sandra » Thu Jan 19, 2012 11:44 am

Hello Sim,
In TeeChartNET3UpdateBuild file,there is no Tchart.dll for .net3.5(3.jpg),but my project is .net3.5.Can we user tchart.dll for .net2.0?
Yes, you can use .net2.0 dll without problems, in your projects made in .net3.5
I have upload the list version in my customer page(1.jpg),please tell me which file is the last version,thanks?
In the customer page you can see TeeChartNET3UpdateBuild, this is the last version 3 update of Febrary, 2010, but before download and Install the update, you need download last version 3 of June, 2009 that in your case you need download TeeChartNet3Vnet2008 and install it. After you can install the TeeChartNet3UpdateBuild
Why the custom labels can not auto Adjust Axis's Label visible?
I recommend that in your case take a look in this thread where is discussing different ways to treat the problem of overlap of labels

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / 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

sim
Newbie
Newbie
Posts: 19
Joined: Wed Jul 30, 2008 12:00 am

Re: Auto Adjust Axis's Label visible when custom label

Post by sim » Mon Jan 30, 2012 3:14 am

I have resolve this like this:

Code: Select all

 void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
   //the current Label  will be hidden when it is overlapped with its previous labels.
            //Get the axis
            Steema.TeeChart.Axis xAxis = tChart1.Axes.Bottom;
            Steema.TeeChart.Axis yAxis = tChart1.Axes.Left;
            xAxis.Labels.Items[0].Visible = true;
            string visibleInfo =  xAxis.Labels.Items[0].Text+":true"+Environment.NewLine;
            for (int i = 1; i < xAxis.Labels.Items.Count; i++)
            {
                var currentLabel = xAxis.Labels.Items[i];
                SizeF currentSize = tChart1.Graphics3D.MeasureString(xAxis.Labels.Font, currentLabel.Text);
                Rectangle currentRect = new Rectangle(xAxis.CalcXPosValue(currentLabel.Value), xAxis.CalcYPosValue(currentLabel.Value), (int)currentSize.Width, (int)currentSize.Height);
                AxisLabelItem lastVisibleLabel = xAxis.Labels.Items.Where(x => x.Visible && IndexOfLabel(xAxis, x.Text) < i).LastOrDefault();//get the nearest visible Label before current Label
                if (lastVisibleLabel == null)
                {
                    currentLabel.Visible = true;
                    continue;
                }
                SizeF lastVisibleSize = tChart1.Graphics3D.MeasureString(xAxis.Labels.Font, lastVisibleLabel.Text);
                Rectangle lasyVisibleRect = new Rectangle(xAxis.CalcXPosValue(lastVisibleLabel.Value), xAxis.CalcYPosValue(lastVisibleLabel.Value), (int)lastVisibleSize.Width, (int)lastVisibleSize.Height);
                if (lasyVisibleRect.X + lastVisibleLabel.Width >= currentRect.X)
                {
                    currentLabel.Visible = false;
                }
                else
                {
                    currentLabel.Visible = true;
                }
                visibleInfo += xAxis.Labels.Items[i].Text + currentLabel.Visible + Environment.NewLine;
            }
  tChart1.Update();
}

       private int IndexOfLabel(Axis axis, string p)
        {
            var labelArray = axis.Labels.Items;

            for (int i = 0; i < labelArray.Count; i++)
            {
                if (labelArray[i].Text == p)
                {
                    return i;
                }
            }
            return -1;
        }
but this will refresh chartView twice,because I have Refresh after AfterDraw event!I did use AfterDraw event because the tChart1.SizeChanged() and tChart1.Resize() can not Calc correct XPosValue and Calc correct YPosValue.
I have uplaod my test project,please check this.
AfterDraw(),SizeChanged() and Resize() have been contained in this project.
please run project ,drag window to a small window,then double click window's hander to maximize window(2.jpg),the Labels don't adjust correctly for SizeChanged() and Resize() .
And then double click window's hander to restore the small window status(3.jpg),the Labels don't adjust correctly for SizeChanged() and Resize().
I don't know what happened.
do you know why SizeChanged and Resize can not do this or there have any other event can do this and not refresh ChartView twice?thanks.
Attachments
teechartScaleOverlapping.zip
(83.07 KiB) Downloaded 477 times
3.jpg
3.jpg (88.88 KiB) Viewed 9441 times
2.jpg
2.jpg (268.3 KiB) Viewed 9450 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Auto Adjust Axis's Label visible when custom label

Post by Sandra » Tue Jan 31, 2012 4:55 pm

Hello sim,

Thanks for your project, but I can not run the project here, seems that the error is in line "xAxis.Labels.Items.Where(x => x.Visible && IndexOfLabel(xAxis, x.Text) < i).LastOrDefault();//get the nearest visible Label before current Label". Can you please send a simple project that we can run as is, here or explain how we can execute this project to check your problem exactly here.

Thanks,
Best Regards,
Sandra Pazos / 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

sim
Newbie
Newbie
Posts: 19
Joined: Wed Jul 30, 2008 12:00 am

Re: Auto Adjust Axis's Label visible when custom label

Post by sim » Thu Feb 02, 2012 6:35 am

May be your Teechart version is defferent with mine.My version is 3.5.3225.32185.I have download the project and add reference: Teechart 3.5.3225.32185. The project run ok.thanks.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Auto Adjust Axis's Label visible when custom label

Post by Sandra » Fri Feb 03, 2012 4:24 pm

Hello sim,

Can you tell us if you have tested your project, using last version 3 of TeeChartFor.Net?

Thanks,
Best Regards,
Sandra Pazos / 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

Post Reply