Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please help - Elegent Time/date coding advice for a graph

Status
Not open for further replies.

joelwenzel

Programmer
Jun 28, 2002
448
Hello,

I am writting an activeX control that I want to graph things in a certain way. My data is stored in 2 vectors, one for the date and the other for the y axis. So far I have been able to sucessfully graph data as a function of cell position. However, graphing data as a function of time is a bit tricky.

what I have done is developed a stupid system for my graphing. What I do is first get a conversion ratio for the y. This is

PixelsPerYUnit = windowheight/(yMax-yMin)

Now I can graph as a function of cell number by just saying

pDC->LineTo(cellNumber, windowheight-(y-yMin)*PixelsPerYUnit)

This just converts whatever my y data spacing to the correct spacing in pixels.

For time, it is much trickier. I have tried doing something similar by setting my

PixelsPerXUnit = width/(number_of_days_in_MaxDate - number_of_days_in_MinDate)

But now I have to convert all my dates into days and then convert them back to dates....that really sucks.

I made my own date class that stores days, months, and years because the CTime class only spans 68 years and I need much more than that.
 
I was thinking of another way I could do this. It isn't good method...just another idea.

I could have an array that contains a map of the pixels. For example, if the height of the screen is 480pixels, I could have 480 elements in my array which would range linearly from the YMin to yMax. If the screen is 800 pixels wide, I could have 800 cells in an array with the values ranging linearly from dataMin to dateMax. Then, for each data point, I just compare the data to the data array and the y value to the y value array to find where the point should be placed on the screen. And putting these date labels on the x-axis would not be very difficult.

Still, the idea kindof sucks since I need to create a new array each time the user changes the screen size and for a number of other reasons as well
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top