Page 1 of 1

how to wrap series labels

Posted: Thu Jul 30, 2009 9:23 am
by 13045482
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.

Re: how to wrap series labels

Posted: Thu Jul 30, 2009 11:12 am
by 10050769
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,

Re: how to wrap series labels

Posted: Thu Jul 30, 2009 11:21 am
by 13045482
thanks but this looks hardcoded, can u make it dynamic as the data will keep on changing and i have many labels?

Re: how to wrap series labels

Posted: Thu Jul 30, 2009 11:32 am
by yeray
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');
        }

Re: how to wrap series labels

Posted: Thu Jul 30, 2009 12:27 pm
by 13045482
thanks

Re: how to wrap series labels

Posted: Thu Jul 30, 2009 2:05 pm
by 13049497
Should this little line work too?

Code: Select all

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

Re: how to wrap series labels

Posted: Thu Jul 30, 2009 2:37 pm
by yeray
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;
        }

Re: how to wrap series labels

Posted: Tue Feb 23, 2010 10:05 am
by 13045482
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.

Re: how to wrap series labels

Posted: Tue Feb 23, 2010 10:47 am
by 13045482
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

Re: how to wrap series labels

Posted: Wed Feb 24, 2010 12:02 pm
by 10050769
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 21602 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,

Re: how to wrap series labels

Posted: Wed Feb 24, 2010 12:19 pm
by 13045482
EXACTLY.. this is the issue i am facing!!!

Re: how to wrap series labels

Posted: Wed Feb 24, 2010 12:24 pm
by 13045482
please let me know how to solve this( which you have reproduced at your end). many thanks.

Re: how to wrap series labels

Posted: Thu Feb 25, 2010 8:11 am
by 13045482
Hi
Any luck? is there any solution to this?

Re: how to wrap series labels

Posted: Thu Feb 25, 2010 9:54 am
by yeray
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

Re: how to wrap series labels

Posted: Wed Mar 03, 2010 12:09 pm
by 13045482
Thanks