I am using a Dynamic Data Display WPF chart. I am trying to set the visible datarect for the Viewport2D in a chart with a datetime axis for x- axis. How do I convert a date into a valid double value for the DataRect which I need to assign to the Visible property on the Viewport2D?
Dynamic Data Display has a ConvertToDouble method used specifically for it's chart's axes. Depending on the type of axis you use, you have to pass in different types, but for DateTimeAxis, it looks like this :
var axis = (DateTimeAxis)plotter.MainHorizontalAxis;
double xMin = axis.ConvertToDouble(date1);
double xMax = axis.ConvertToDouble(date2);
Rect visibleRect = new Rect(xMin, 0, xMax - xMin, 1 - 0);
//not sure what bounds you want for y axis, so assumed 1 for example purposes.