1
Answer

Drawing and scaling

Ask a question
Administrator

Administrator

21y
1.7k
1
Daniel Stefanescu posted an article and code that demonstrates drawing a line chart. I understand most of what is going on. I am stumped by the scaling code. Here is that snippet. XScale = (myRect.Width / (this.chartData.XValues.Length - 1)); a = (myRect.Height / (YMax - YMin)); b = -YMin * a; YScale = (myRect.Height / YMax); for (i = 0; i < this.chartData.XValues.Length; i++) { myX = XScale * i; myY = myRect.Height - (a * line.Values[i] + b); LinePoints[i] = new PointF(myX, myY); } myGraphics.DrawLines(LinePen, LinePoints); The entire article is titled "A Variety of Chart Engines". I changed two of the object names to make them more meaningful to me and removed some spaces. Other than that, the code is the same as in the article. Could someone explain the point of this code? How does this create the image to the appropriate size? I am guessing that's what it does.

Answers (1)