Page 1 of 1

LegendScrollBar problem with Inverted Legend

Posted: Mon Aug 09, 2010 10:43 am
by 9641422
I have a chart with Legend visible and a LegendScrollBar added. We needed to have the ordering for legend reversed so I added Legend.Inverted=True to my code. The legend inverted all right but the LegendScrollBar didn't and now the scroll bar is working opposite to expectation.

I couldn't find any API to invert the LegendScrollBar as well. I also tried inverting the legend both before and after the LegendScrollBar was added - no effect.

Any ideas?

We are currently using Teechart .Net 2 for VS2005

Re: LegendScrollBar problem with Inverted Legend

Posted: Wed Aug 11, 2010 3:57 pm
by yeray
Hi Amol

This is a known bug already in the defect list to be fixed in future releases (TV52012536).
The only workaround I can think on is not to set the Inverted property and use GetLegendText to invert the strings. For example:

Code: Select all

        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;

            Steema.TeeChart.Styles.FastLine fast1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);

            for (int i = 0; i < 200; i++)
            {
                fast1.Add(i);
            }

            //tChart1.Legend.Inverted = true;
            Steema.TeeChart.Tools.LegendScrollBar legendscroll1 = new Steema.TeeChart.Tools.LegendScrollBar(tChart1.Chart);

            tChart1.GetLegendText += new Steema.TeeChart.GetLegendTextEventHandler(tChart1_GetLegendText);
        }

        void tChart1_GetLegendText(object sender, Steema.TeeChart.GetLegendTextEventArgs e)
        {
            e.Text = tChart1[0].YValues[tChart1[0].Count - e.Index - 1].ToString();
        }

Re: LegendScrollBar problem with Inverted Legend

Posted: Thu Aug 12, 2010 12:49 pm
by 9641422
Thats too bad.

The workaround works but only for the text. Since we are also using groups, series colours, and check boxes, simply correcting the text would not be sufficient.

Is a workaround possible by inverting the legend positions with GetLegendPos() ? Or does that event only controls the complete legend rectangle and not the individual series?


As an addition, the problem is coming because we are using both stacked area series and unstacked point and line series in the same chart. This works only when the stacked series are added first - otherwise the unstacked point and line series become stacked as well. However, in the legend it is a requirement to show the point and line series first.

With this scenario, is there a better workaround possible?

Re: LegendScrollBar problem with Inverted Legend

Posted: Fri Aug 13, 2010 1:13 pm
by yeray
Hi Amol,
Amol wrote:Is a workaround possible by inverting the legend positions with GetLegendPos() ? Or does that event only controls the complete legend rectangle and not the individual series?
This event gives you the coordinates where each item of the legend is going to be drawn. You could use it to draw your text manually over the legend but it won't change the checkboxes behaviour.
Amol wrote:As an addition, the problem is coming because we are using both stacked area series and unstacked point and line series in the same chart. This works only when the stacked series are added first - otherwise the unstacked point and line series become stacked as well. However, in the legend it is a requirement to show the point and line series first.
It doesn't happen with the latest version of TeeChart for .NET so I recommend you to try it: http://www.steema.com/evaluation/net

Here the following seems to work as expected:

Code: Select all

        Random rnd;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Legend.CheckBoxes = true;

            Steema.TeeChart.Styles.Points points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            Steema.TeeChart.Styles.Area area1 = new Steema.TeeChart.Styles.Area(tChart1.Chart);
            Steema.TeeChart.Styles.Area area2 = new Steema.TeeChart.Styles.Area(tChart1.Chart);

            rnd = new Random();
            for (int i = 0; i < tChart1.Series.Count; i++)
            {
                if (tChart1[i] is Steema.TeeChart.Styles.Area)
                    AddValues(i, 0);
                else
                    AddValues(i, 100);
            }

            points1.Stacked = Steema.TeeChart.Styles.CustomStack.None;
            line1.Stacked = Steema.TeeChart.Styles.CustomStack.None;
            area1.Stacked = Steema.TeeChart.Styles.CustomStack.Stack;
            area2.Stacked = Steema.TeeChart.Styles.CustomStack.Stack;

            Bitmap b = tChart1.Bitmap;
            tChart1.Axes.Left.Automatic = false;
        }

        private void AddValues(int SeriesIndex, int MinValue)
        {
            tChart1[SeriesIndex].Add(MinValue + rnd.NextDouble() * 100);
            for (int i = 1; i < 10; i++)
                tChart1[SeriesIndex].Add(tChart1[SeriesIndex].YValues[i - 1] + rnd.NextDouble() * 10 - 4.5);
        }
However, note that adding the area series after the other, make them to be drawn the lasts, so they can overlap the point or the line series if they have similar YValues.
So probably the best way to do this would be creating your own custom legend manually.

Re: LegendScrollBar problem with Inverted Legend

Posted: Tue Jun 16, 2020 6:53 am
by 15688831
It's been a while since last post here, but issue is still reproducible for me even on TeeChart 4.2020.5.12 version.

Inverted legend also has inverted scrolling Is it possible to get inverted legend without scrolling affected?

Thank you.

Re: LegendScrollBar problem with Inverted Legend

Posted: Wed Jun 17, 2020 4:06 pm
by Christopher
wrote:
Tue Jun 16, 2020 6:53 am
Inverted legend also has inverted scrolling Is it possible to get inverted legend without scrolling affected.
You could try something like this:

Code: Select all

        private void InitializeChart()
        {
            var line = new Line(_tChart.Chart);

            for (int i = 0; i < 100; i++)
            {
                line.Add(i);
            }

            _tChart.Legend.FirstValue = line.Count - 20;

            _tChart.Legend.Inverted = true;

            _tChart.Tools.Add(typeof(LegendScrollBar));
        }