Hi Chris,
I figure it would be too complicated to attach the project since it is rather large and relies on many other files to get data, etc. So I'm hoping you can at least help with some of the general logic. I'll describe what I've done so far:
Here are my axis events:
Code: Select all
void CWFGraphDlg::OnBeforeDrawAxesTchart1()
{
_Count = 0;
_Increment1Percentage = 0;
_Increment2Percentage = 0;
}
void CWFGraphDlg::OnGetAxisLabelTchart1(long Axis, long SeriesIndex, long ValueIndex, BSTR* LabelText)
{
// To line up the top axis, we need to first get the bottom axis increments
// When labels are rounded off, the increment between the first label and max point is different
// than the rest(while automatic), hence _Increment1 and _Increment2
// 1st time called, LabelText is maximum, 2nd is minimum, 3rd is the first auto generated label below max
if ( _SyncAxes )
{
if ( Axis == atBottom )
{
double max = m_Chart1.GetAxis().GetBottom().GetMaximum();
double min = m_Chart1.GetAxis().GetBottom().GetMinimum();
if ( (max != min) && (max > 0.00000001) ) // if you retrieve max of 0, it's not exactly 0
{
_Count++;
CString labelText = *LabelText;
labelText.Remove(',');
if ( _Count == 3 )
{
_FirstLabel = atof(labelText);
_Increment1Percentage = (max - _FirstLabel) / (max-min);
}
if ( _Count == 4 )
_Increment2Percentage = (_FirstLabel - atof(labelText)) / (max-min);
}
}
}
}
void CWFGraphDlg::OnGetNextAxisLabelTchart1(long Axis, long LabelIndex, double* LabelValue, BOOL* MoreLabels)
{
// This function allows us to manually set each label, it is called after OnGetAxisLabel
// It will be called as long as MoreLabels = true and LabelValue > min
if ( _SyncAxes )
{
if ( Axis == atTop )
{
double max = m_Chart1.GetAxis().GetTop().GetMaximum();
double min = m_Chart1.GetAxis().GetTop().GetMinimum();
// if you retrieve max of 0, it's not exactly 0
if ( (max != min) && (max > 0.00000001) && (_Increment2Percentage != 0) )
{
*MoreLabels = true;
if ( LabelIndex == 0 ) // The first label is max - increment1
{
*LabelValue = max - (_Increment1Percentage*(max-min));
_FirstLabel = *LabelValue;
}
else // Every other label is previous label - increment2
{
*LabelValue = _FirstLabel - (_Increment2Percentage*(max-min));
_FirstLabel = *LabelValue;
}
}
}
}
}
Now, in my main graph function, I want to determine the max/min for top axis so the labels fall on more even numbers. Here's the logic I've tried first:
1. Determine a suitable increment based on range of top axis
2. Round off the max/min for both axes to nearest decimal
3. Increase the top axis by increment until it is equally divisable by or into bottom axis.
This actually works most of the time, but not if the difference between top and bottom scales is very large, or some other factors, I don't know.
Then I tried determining the top and bottom intervals, based on 1, 2 or 5, and the number of intervals. Then increasing the top axis until it's number of intervals is equally divisable by bottom number. Then make sure the remaining percentage is the same for top and bottom. This also works, almost, but doesn't round off very nice and sometimes get infinite loops because of the precision I have to use.
So this is where I'm stuck, any suggestions would be helpful. Thank you