ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  [MFC] Any ways to get starting Xaxis from the current Plot Area.
Posted by Kaiden on Feb-12-2014 20:31
Attachments:
Hi Peter,
When I zoom in and move sideways with the scroll bar, everything moves along with it
right? is there a way to get the current starting xaxis from the Plot Area?
Could you have a look at the picture and the code??

Thanks alot Peter! :)
Best Regards,
Hayoung Kwon

//inside drawChar(CChartViewer *viewer)
int ColorSet[4] = {0x80000000+0xf00000, 0x80000000+0x00ff00, 0x80000000+0x00fff0,
0x80000000+0x309ff0};

// No of file
int NoOfFile = m_pDoc->m_NoOfFile;
if(NoOfFile == 0)
return;

int nNoOfCollum = m_pDoc->m_NoOfCollum-1;
double** dXAxisTime;
double** dYAxisLevel;
double* dFullRangeScale; //set range of xaxis for zoom

dFullRangeScale = new double[NoOfFile];

for (int i=0; i<NoOfFile; i++)
{
dXAxisTime = new double*[NoOfFile];
dYAxisLevel = new double*[NoOfFile];
}

for (int i=0; i<NoOfFile; i++)
{
dXAxisTime[i] = new double[(signed)m_pDoc->m_vDoubleTime[i].size()];
dYAxisLevel[i] = new double[(signed)m_pDoc->m_vDoubleLevel[i].size()];
dFullRangeScale[i] = (signed)m_pDoc->m_vDoubleLevel[i].size(); //get the
length of each file's xaxis
}


for (int i=0; i<NoOfFile; i++)
{
for (int j=0; j<(signed)m_pDoc->m_vDoubleTime[i].size(); j++)
{
dXAxisTime[i][j] = m_pDoc->m_vDoubleTime[i][j];
dYAxisLevel[i][j] = m_pDoc->m_vDoubleLevel[i][j];
}
}

double dLongestRange=0;

for(int iFile=0; iFile< NoOfFile; iFile++)
{
double tempCurrent = dFullRangeScale[iFile];
if(iFile==0)
{
dLongestRange = tempCurrent;
continue;
}

if(dLongestRange < tempCurrent)
dLongestRange = tempCurrent;
}

m_pChart = new XYChart(m_nWindowWidth - 30, 425, 0xf0f0f0, 0x80000000 +
0xFF7200);


int nWidthPlot = m_pChart->getWidth() - 67;
int nHeightPlot = m_pChart->getHeight()-110;
m_pChart->setPlotArea(50, 30, nWidthPlot, nHeightPlot, Chart::Transparent, -1,
Chart::Transparent, 0x80000000 + 0xD2D2D2, Chart::Transparent);

m_pChart->setClipping();

double startLabelIndex = m_ctrlChart.getValueAtViewPort("x",
m_ctrlChart.getViewPortLeft());
double endLabelIndex = m_ctrlChart.getValueAtViewPort("x",
m_ctrlChart.getViewPortLeft() + m_ctrlChart.getViewPortWidth());
double dTotalLabelIndex = endLabelIndex - startLabelIndex;

int nTotalLabel = (int)dTotalLabelIndex;

m_pChart->xAxis()->setLabelStep(0, 0, 0,  -0x7fffffff);

m_ctrlChart.syncLinearAxisWithViewPort("d", m_pChart->xAxis());
m_ctrlChart.setScrollDirection(Chart::DirectionHorizontalVertical);
m_ctrlChart.setZoomDirection(Chart::DirectionHorizontalVertical);
m_ctrlChart.setZoomInWidthLimit(0.0002);

vector< StepLineLayer* > vecLineLayer;

vector< CString > vLegend;
for (int i=0; i<8; i++)
{
CString strLegend;
strLegend.Format(_T("NO%d"), i+1);
vLegend.push_back(strLegend);
}

for(int iLayerIdx = 0; iLayerIdx<NoOfFile; iLayerIdx++)
{
StepLineLayer* layer = m_pChart-
>addStepLineLayer(DoubleArray(dYAxisLevel[iLayerIdx], (signed)m_pDoc-
>m_vDoubleTime[iLayerIdx].size()), ColorSet[iLayerIdx], "");

vecLineLayer.push_back(layer);
}

for(int i=0; i<NoOfFile; i++)
{

vecLineLayer[i]->setXData(DoubleArray(dXAxisTime[i], (signed)m_pDoc-
>m_vDoubleTime[i].size()));
vecLineLayer[i]->setLineWidth(2);
}

m_pChart->yAxis()->setMinTickInc(1);
m_pChart->xAxis()->setTickDensity(100);
m_pChart->xAxis()->setDateScale("{value|hh:nn:ss.fff}");
m_pChart->xAxis()->setLabelStyle("arialbd.ttf", 7, 0x008000)->setFontAngle(45);

m_ctrlChart.setChart(m_pChart);
xaxisValue.png

  Re: [MFC] Any ways to get starting Xaxis from the current Plot Area.
Posted by Peter Kwan on Feb-13-2014 00:36
Hi Kaiden,

After you call setChart to draw and display the chart, the x-axis scale can be obtained
using Axis.getMinValue and Axis.getMaxValue. For example:

.... after calling setChart ....

double xMin = c->xAxis()->getMinValue();

Hope this can help.

Regards
Peter Kwan

  Re: [MFC] Any ways to get starting Xaxis from the current Plot Area.
Posted by Kaiden on Feb-20-2014 10:30
Thanks Peter!!!
That's exactly what I was looking for!! :)

Kaiden.

  Re: [MFC] Any ways to get starting Xaxis from the current Plot Area.
Posted by Kaiden on Feb-20-2014 15:47
Hi Peter,
I have one more thing.
Can you do something reverse it??

before we used getMinValue() to get the smallest xaxias value from the current plot area.

can we set the plot to a value that I want in xaxis?? I thought there would be something
like setMinValue() and the viewport would change automatically, but sadly nothing like that.

I know there's something similar, onviewportchanged.
but anyway to move the chart to somewhere in the x-point where I want to??

Thank you Peter!

Best Regards,
Kaiden

  Re: [MFC] Any ways to get starting Xaxis from the current Plot Area.
Posted by Peter Kwan on Feb-21-2014 02:17
Hi Kaiden,

In many applicaitons, if the x-axis starting point is moved, not only the chart needs to be
updated, but other GUI elements may need to be updated too. For example, in your case,
you may need to update the scrollbar too.

The ViewPort and ViewPortChanged event is designed to faciliate these types of updates.
When the axis needs to change for any reason (drag on the chart to scroll or zoom,
clicking on a "Show Last 90 days" button, dragging on the scroll bar, selecting dates from
a calendar control, etc), the view port is modified to represent the necessary change,
and a ViewPortChanged event is triggered so that the chart and other controls that
needs to update can be changed.

If your code needs to update the x-axis starting point for some reason, the suggested
method is the same as above - modify the view port to reflect the necessary change,
then call "CChartViewer::updateViewPort" to trigger the ViewPortChanged event. If your
existing GUI is working, I suppose you already have all the code to handle the
ViewPortChanged event, so you only need to set the view port to reflect the change.

If you want to have a specific value for the starting point of the x-axis, you may obtain
its view port position using CChartViewer::getViewPortAtValue, and set this value as the
left side of the view port (using setViewPortLeft), then call
CChartViewer::updateViewPort to trigger the event.

Note that modifying the left side of the view port is the same as scrolling the chart. If
you do not want the chart to scroll (want to keep the right side unchanged), you would
need to modify the view port width as well (using setViewPortWidth) to keep the right
side unchanged.

Hope this can help.

Regards
Peter Kwan