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

Message ListMessage List     Post MessagePost Message

  WPFViewPortControl is not working correctly when reverse x axis
Posted by Miles on Jul-18-2019 22:21
Dear Support,

I have found that when you reverse the WPFViewPortControl X axis, it would't work correctly.

When the WPFViewPortControl X axis is not reversed, drag the rectangle to move the viewport the startX and endX will matched correctly. But here is the problem after reverse the x axis WPFViewPortControl rectangle wouldn't match WPFChartViewer startX and endX.

If the x range is like 0 ~ 5000, and WPFViewPortControl rectangle startX and endX is 200 ~ 300, then the WPFChartViewer startX and endX will be 4800 ~ 4700 ..

Thanks

  Re: WPFViewPortControl is not working correctly when reverse x axis
Posted by Miles on Jul-19-2019 09:08
Attachments:
Please see Attachment which contains more information.

Thanks
2019-07-19 09_06_01-.png

  Re: WPFViewPortControl is not working correctly when reverse x axis
Posted by Peter Kwan on Jul-19-2019 13:35
Hi Miles,

The WPFViewPortControl basically is just an enhanced "scroll bar" with a "background image". In the sample code, we set the background image to a chart that matches the "full range", so it appears the selection in the WPFViewPortControl matches the actual data shown in the main chart.

You can in fact set the image of the WPFViewPortControl to anything you like. Sometimes people will show a different chart in the WPFViewPortControl, or just an image of a "calendar" there. The image shown in the WPFViewPortControl will not affect the actual data range of the top chart. The actual data range is always based on the "full range".

So for your case, instead of using Axis.setReverse, you can simply reverse the full range:

//viewer.setFullRange("x", timeStamps[0], timeStamps[timeStamps.Length - 1]);
viewer.setFullRange("x", timeStamps[timeStamps.Length - 1], timeStamps[0]);

After the above, all the axis scale will be consistent. However, there is still an issue in data acquisition. In the original sample code, it is selecting data between the startDate and endDate using some code that is equivalent to ((timeStamp >= startDate) and (timeStamp <= endDate)), The code implicitly assumes startDate > endDate, while is not the case for a reversed range. So I suggest to add the following code to check and swap the startDate and endDate if necessary.

// Put the following line just before the "int startIndex = .... " line
if ((viewPortEndDate - viewPortStartDate).TotalMilliseconds < 0)
{
    DateTime temp = viewPortStartDate;
    viewPortStartDate = viewPortEndDate;
    viewPortEndDate = temp;
}

Hope this can help.

Regards
Peter Kwan

  Re: WPFViewPortControl is not working correctly when reverse x axis
Posted by Miles on Jul-19-2019 15:00
Dear Peter,

  Thank you so much for your answer

Thanks