Page 1 of 1

How to change series marks default position for zero Y value

Posted: Wed Jul 15, 2009 6:47 am
by 9641771
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?

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

Posted: Wed Jul 15, 2009 11:53 am
by yeray
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);
                }
            }
        }

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

Posted: Thu Jul 16, 2009 6:06 am
by 9641771
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?

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

Posted: Thu Jul 16, 2009 10:23 am
by 10050769
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,