How to change series marks default position for zero Y value

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
bairog
Newbie
Newbie
Posts: 72
Joined: Fri Jul 07, 2006 12:00 am
Location: Moscow, Russia
Contact:

How to change series marks default position for zero Y value

Post by bairog » Wed Jul 15, 2009 6:47 am

I have a chart with two bar graphs (one is for positive values and enother is for negative). One is drawing above enother. Both graphs have marks.

After adding for example (0, 1) for first graph and (0, 0) for second I can see two overlapping marks for that points:
Image

This is because the default position of mark for zero Y value is above corresponding point. I know that my second bar has values that are >=0, so I want to ensure that all marks (including zero mark) will be below corresponing points.

How can I do that?
Thank you.

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

Re: How to change series marks default position for zero Y value

Post by Yeray » Wed Jul 15, 2009 11:53 am

Hi

Take a look at the following example of how you could recalculate the mark ant the arrow position in OnAfterDraw event:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        Bar bar1, bar2;

        private void InitializeChart()
        {
            chartController1.Chart = tChart1;

            tChart1.Aspect.View3D = false;
            tChart1.Legend.Visible = false;
            tChart1.Dock = DockStyle.Fill;

            bar1 = new Bar(tChart1.Chart);
            bar2 = new Bar(tChart1.Chart);

            bar1.FillSampleValues(3);
            bar2.Add(0);
            bar2.Add(-50);
            bar2.Add(-20);

            bar1.MultiBar = MultiBars.Stacked;

            bar1.Marks.Arrow.Color = Color.Black;
            bar2.Marks.Arrow.Color = Color.Black;

            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
            tChart1.Draw();
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            for (int i = 0; i < tChart1[0].Count; i++)
            {
                if (bar2.YValues.Value[i] == 0)
                {
                    bar2.Marks.Positions[i].Custom = true;
                    bar2.Marks.Positions[i].LeftTop.Y = tChart1.Axes.Left.CalcYPosValue(0) + bar2.Marks.ArrowLength;
                    bar2.Marks.Positions[i].ArrowFrom.Y = tChart1.Axes.Left.CalcYPosValue(0);
                    bar2.Marks.Positions[i].ArrowTo.Y = tChart1.Axes.Left.CalcYPosValue(0) + bar2.Marks.ArrowLength;
                    bar2.Marks.Positions[i].LeftTop.X = tChart1.Axes.Bottom.CalcXPosValue(i) - bar2.Marks.Positions[i].Width/2;
                    bar2.Marks.Positions[i].ArrowFrom.X = tChart1.Axes.Bottom.CalcXPosValue(i);
                    bar2.Marks.Positions[i].ArrowTo.X = tChart1.Axes.Bottom.CalcXPosValue(i);
                }
            }
        }
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

bairog
Newbie
Newbie
Posts: 72
Joined: Fri Jul 07, 2006 12:00 am
Location: Moscow, Russia
Contact:

Re: How to change series marks default position for zero Y value

Post by bairog » Thu Jul 16, 2009 6:06 am

I've tried to compile your example "as-is" but faced two mistakes:

1) I don't know what chartController1 is because it is not defined.
So I simply deleted that string from your example.
Is that string useful and for what purpuse?

2) Steema.TeeChart.TChart.Draw method correct prototype is public Void Draw(Graphics g). At least for the latest teeChart V2 build that I'm using.
First I've tried to simply remove that string, but after that example worked strange. Using breakpoints I've found that tChart1_AfterDraw event was called at first paint but marks still overlapping. And only after form manipulations (moving, minimize and maximize again, etc.) which enforced redrawing and calling tChart1_AfterDraw again everything become fine.
So I changed that string from your example to tChart1.Draw(this.CreateGraphics()). After that everything worked fine.
Further investigations discovered that zooming and scrolling are working the same way as in situation when I simply deleted that string (working correctly only after enforced form redrawing). So it is clear that calling Draw method is neccesary at least inside tChart1_Zoomed, tChart1_UndoneZoom and tChart1_Scroll events. As far as I know this enforces double repainting and make program run two times slower (correct me if I'm wrong).

Could you explain me why calling Draw method programmatically is so neccesary? Is it some kind of trick? Isn't that method called automatically while painting form? And why when I deleted that string decpite of calling tChart1_AfterDraw event labels still overlapping? Are there other situations or events not described above in which Draw method must be called programmatically?
Thank you.

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

Re: How to change series marks default position for zero Y value

Post by Sandra » Thu Jul 16, 2009 10:23 am

Hello, bairog

1) I don't know what chartController1 is because it is not defined.
So I simply deleted that string from your example.
Is that string useful and for what purpuse?
ChartController element of TeeChart is same that Commander element of TeeChart, but ChartController element is used in last versions of TeeChartFor .Net ( version 3 and 4). On the other hand, this only used for test the program, so if you want you could remove or if you want to use you must change ChartController for Commander.
2) Steema.TeeChart.TChart.Draw method correct prototype is public Void Draw(Graphics g). At least for the latest teeChart V2 build that I'm using.
Also, you can use for draw, Bitmap b = tChart1.Bitmap, for repaint the chart. This method allow do the same with draw. You needs, too, put Bitmap b= tChart1.Bitmap in the next events, because projects works fine:

Code: Select all

            tChart1.Zoomed += new EventHandler(tChart1_Zoomed);
            tChart1.UndoneZoom += new EventHandler(tChart1_UndoneZoom);
            tChart1.Scroll += new EventHandler(tChart1_Scroll);
Could you explain me why calling Draw method programmatically is so neccesary? Is it some kind of trick?
Is necessary if you want draw, when you recalculate values internally for example, when you use AfterDraw event,after you needs draw chart updated, because new values appears correctly.
And why when I deleted that string decpite of calling tChart1_AfterDraw event labels still overlapping?
We must force chart to be painted again, because puts labels correctly in the chart.
Are there other situations or events not described above in which Draw method must be called programmatically?
All the situations, that you needs to recalculate internally values of the chart.

I hop will hepls you.

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