how to wrap series labels

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

how to wrap series labels

Post by Neelam » Thu Jul 30, 2009 9:23 am

hi
I have a stacked bar cahrt. I want that labels should be wrapped when ever there is space between them.That is suppose label is "JJ HH NN". so it should show as

JJ
HH
NN

How to do this?.. thanks.

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

Re: how to wrap series labels

Post by Sandra » Thu Jul 30, 2009 11:12 am

Hello shikha,

I made a simple project, that I think helps, for put labels series wrap. Please see next code and check works correctly in your applicaiton.

Code: Select all

 public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            
            Steema.TeeChart.Styles.Bar bar = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            Steema.TeeChart.Styles.Bar bar2 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            tChart1.Panel.MarginBottom = 12;
            bar.FillSampleValues();
            bar1.FillSampleValues();
            bar2.FillSampleValues();
            bar.Marks.Visible = false;
            bar1.Marks.Visible = false;
            bar2.Marks.Visible = false;
            bar.MultiBar = Steema.TeeChart.Styles.MultiBars.Stacked;
            for (int i = 0; i < bar.Count; i++)
            {
                bar.Labels[i] = "JJ" + "\n"+"HH" + "\n"+"NN" + "\n";
            }
        }
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

Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

Re: how to wrap series labels

Post by Neelam » Thu Jul 30, 2009 11:21 am

thanks but this looks hardcoded, can u make it dynamic as the data will keep on changing and i have many labels?

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: how to wrap series labels

Post by Yeray » Thu Jul 30, 2009 11:32 am

Hi shikha,

You could use OnGetAxisLabels to retrieve each label text and modify it as you wish. For example you could change the 'space' for '\n':

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;

            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            Steema.TeeChart.Styles.Bar bar2 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            Steema.TeeChart.Styles.Bar bar3 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            tChart1.Panel.MarginBottom = 12;
            bar1.FillSampleValues();
            bar2.FillSampleValues();
            bar3.FillSampleValues();
            bar1.Marks.Visible = false;
            bar2.Marks.Visible = false;
            bar3.Marks.Visible = false;
            bar1.MultiBar = Steema.TeeChart.Styles.MultiBars.Stacked;
            for (int i = 0; i < bar1.Count; i++)
            {
                bar1.Labels[i] = "JJ HH NN";
            }

            tChart1.Axes.Bottom.GetAxisDrawLabel += new GetAxisDrawLabelEventHandler(Bottom_GetAxisDrawLabel);
        }

        void Bottom_GetAxisDrawLabel(object sender, GetAxisDrawLabelEventArgs e)
        {
            e.Text = e.Text.Replace(' ', '\n');
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

Re: how to wrap series labels

Post by Neelam » Thu Jul 30, 2009 12:27 pm

thanks

AIS
Newbie
Newbie
Posts: 70
Joined: Wed Jun 25, 2008 12:00 am

Re: how to wrap series labels

Post by AIS » Thu Jul 30, 2009 2:05 pm

Should this little line work too?

Code: Select all

tcChart.Axes.Bottom.Labels.MultiLine = true;

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: how to wrap series labels

Post by Yeray » Thu Jul 30, 2009 2:37 pm

Hi AIS,

That's for being used with datetimes, as the help says.
Steema.TeeChart.AxisLabels.MultiLine Property help wrote:Activate Multiline Axis Labels. TeeChart will automaticall break DateTime Labels on occurence of a space " ". Use '\n' in other label types to break a line or use the SplitInLines method in the OnGetAxisLabel event.
For example:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;

            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            Steema.TeeChart.Styles.Bar bar2 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            Steema.TeeChart.Styles.Bar bar3 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            tChart1.Panel.MarginBottom = 12;
            bar1.FillSampleValues();
            bar2.FillSampleValues();
            bar3.FillSampleValues();
            bar1.Marks.Visible = false;
            bar2.Marks.Visible = false;
            bar3.Marks.Visible = false;
            bar1.MultiBar = Steema.TeeChart.Styles.MultiBars.Stacked;

            bar1.XValues.DateTime = true;
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy hh:mm:ss";
            tChart1.Axes.Bottom.Labels.MultiLine = true;
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

Re: how to wrap series labels

Post by Neelam » Tue Feb 23, 2010 10:05 am

This code
e.LabelText = e.LabelText.Replace(" ", "\n")
is not working-
its giving \n within text.
That is if label is xx yy zz then using his gives xx\nyy\nzz

plesae let me know what to do.

Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

Re: how to wrap series labels

Post by Neelam » Tue Feb 23, 2010 10:47 am

doing by using ControlChars.NewLine or vbCrLf ( i am using vb.net, so that was the reason probably \n did not work). But now i am facing another issue. I am using data table tool and doing this is inserting empty rows in that . So for example if in my label i am giving one carriage return that in data table also its inserting one empty row , if i m giving twoe carriage return that in data table also its inserting two empty row like this-

bar1 66 88

bar2 88 99

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

Re: how to wrap series labels

Post by Sandra » Wed Feb 24, 2010 12:02 pm

Hello shikha,

Using last version 4 and last version 3 of TeeChart.Net, chart appears next image using this code:

Code: Select all

Private Sub InitializeChart()
        TChart1.Aspect.View3D = False
        Dim datatool1 As Steema.TeeChart.Tools.DataTableTool = New Steema.TeeChart.Tools.DataTableTool(TChart1.Chart)
        Dim bar1 As Steema.TeeChart.Styles.Bar = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
        Dim bar2 As Steema.TeeChart.Styles.Bar = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
        TChart1.Header.Visible = False
        bar1.FillSampleValues()
        bar2.FillSampleValues()
        bar1.Marks.Visible = False
        bar2.Marks.Visible = False
        bar1.MultiBar = Steema.TeeChart.Styles.MultiBars.Stacked
        Dim i As Integer
        For i = 0 To bar1.Count - 1
            bar1.Labels(i) = "JJ HH"
        Next
        datatool1.RowPen.Visible = True
        datatool1.RowPen.Color = Color.Black
        datatool1.ColumnPen.Visible = True
        datatool1.ColumnPen.Color = Color.Black
        AddHandler TChart1.Axes.Bottom.GetAxisDrawLabel, AddressOf Me.Bottom_GetAxisDrawLabel
    End Sub
    Private Sub Bottom_GetAxisDrawLabel(ByVal sender As Object, ByVal e As Steema.TeeChart.GetAxisDrawLabelEventArgs)
        e.Text = e.Text.Replace(" ", vbLf)
    End Sub
Chart1.png
Chart with v4 and v3 TeeChart.Net
Chart1.png (9.34 KiB) Viewed 22789 times
Please, could you say if this is your problem?
If it isn't your problem, please you could send us a simple project, because we can reproduce your problem 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

Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

Re: how to wrap series labels

Post by Neelam » Wed Feb 24, 2010 12:19 pm

EXACTLY.. this is the issue i am facing!!!

Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

Re: how to wrap series labels

Post by Neelam » Wed Feb 24, 2010 12:24 pm

please let me know how to solve this( which you have reproduced at your end). many thanks.

Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

Re: how to wrap series labels

Post by Neelam » Thu Feb 25, 2010 8:11 am

Hi
Any luck? is there any solution to this?

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: how to wrap series labels

Post by Yeray » Thu Feb 25, 2010 9:54 am

Hi shikha,

You could change the series' labels when you want, something like following:

Code: Select all

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

        private void WrapLabels(Steema.TeeChart.Styles.Bar bar)
        {
            int maxHeight = 0;
            int tmpHeight;
            for (int i = 0; i < bar1.Count; i++)
            {
                bar1.Labels[i] = bar1.Labels[i].Replace(" ", "\n");
                tmpHeight = (int)tChart1.Graphics3D.TextHeight(bar1.Labels[i]);
                if (tmpHeight > maxHeight) maxHeight = tmpHeight;
            }
            datatool1.AutoPosition = false;
            tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
            tChart1.Panel.MarginBottom = maxHeight + tChart1.Series.Count * (int)tChart1.Graphics3D.TextHeight("S");
            tChart1.Panel.MarginLeft = 15;
            tChart1.Panel.MarginTop = 10;
            datatool1.Top = tChart1.Axes.Bottom.Position + (maxHeight/3);
        }     
If you are looking for prioritary support you you may be interested in knowing of our Pro-Support service:

http://www.steema.com/licensing/support
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

Re: how to wrap series labels

Post by Neelam » Wed Mar 03, 2010 12:09 pm

Thanks

Post Reply