0

Working on a private stock chart where I use a rendering rectangle with an origin at lower left and inverted y axis, scale factor y is negative. Y axis ticks render nicely but drawing text (drawstring) is where I run into problems.

            using (Pen pen = new Pen(_color))
            using (Font drawFont = new Font("Arial", 16))
            using (SolidBrush drawBrush = new SolidBrush(Color.Black))
            {
                pen.Width = 1F / e.Graphics.DpiX;
                foreach (float tick in this.TimeSeriesPanelControl.YTicks)
                {
                    e.Graphics.DrawLine(pen, right, tick, right + 10, tick);
                    // this is not producing text to the right of the tick that renders properly.
                    e.Graphics.DrawString(tick.ToString("F2"), drawFont, drawBrush, right + 15, tick);
                }
            }

I have seen that the text is upside down caused by the negative scale factor on the y coordinate.

The question is how to make drawstring render the text to the right of the tick?

  • Where are the transformation Matrices? How are they applied (in which order). What does *negative scale factor* mean? This is wrong: `pen.Width = 1F / e.Graphics.DpiX;` – Jimi Mar 09 '20 at 13:03
  • I mean, did you apply `e.Graphics.TranslateTransform(0, [Canvas.Height]);` and `e.Graphics.ScaleTransform([ScaleX], [ScaleY]);`, or did you multiply two Matrices and then set `e.Graphics.Transform = [Mul-Matrices]`? – Jimi Mar 09 '20 at 14:11
  • Initially >e.Graphics.TranslateTransform(0, this.ClientRectangle.Height); >e.Graphics.ScaleTransform(1, -1); Then later in OnPaint when min and max y and origin y are known: >e.Graphics.TranslateTransform(70, originY); >e.Graphics.ScaleTransform(1, scaleY); That does render curves and y ticks nicely. Problem is with the tick labels as indicated. – user3351749 Mar 09 '20 at 18:26
  • Initially e.Graphics.TranslateTransform(0, this.ClientRectangle.Height); e.Graphics.ScaleTransform(1, -1); Then later in OnPaint when min and max y and origin y are known: e.Graphics.TranslateTransform(70, originY); e.Graphics.ScaleTransform(1, scaleY); That does render curves and y ticks nicely. Problem is with the tick labels as indicated. – user3351749 Mar 09 '20 at 18:32
  • fixed it by removing all transforms and transforming everything myself which leads to a more to the point solution – user3351749 Mar 10 '20 at 15:29

0 Answers0