I've created a DateTime value from an item being clicked in a listBox. It's in the format dd/MM/yyyy hh:mm:ss
. I'm want to zoom in on a ten minute period with the clicked event in the middle. My current code is as follows (where zoom_time is the DateTime to zoom to on my chart;
chart1.ChartAreas[0].AxisX.Minimum = (Convert.ToDouble(zoom_time.AddMinutes(-5)));
chart1.ChartAreas[0].AxisX.Maximum = (Convert.ToDouble(zoom_time.AddMinutes(5)));
This breaks saying
"invalid cast from DateTime to double"
Any ideas guys?
You can use datenum to convert each your data to double.
FromOADate() method in C# is used to return a DateTime equivalent to the specified OLE Automation Date.
You can use the DisplayFormat data annotation attribute on the model property to specify the format and ensure that the format also applies when the value is in "edit mode" (a form control): [BindProperty, DisplayFormat(DataFormatString = "{0:yyyy-MM-ddTHH:mm}", ApplyFormatInEditMode = true)]
You can use DateTime.ToOADate()
, if you mean ole automation date by double
Thanks for that!
For reference, the following works best;
double start = (zoom_time.AddMinutes(-1)).ToOADate();
double end = (zoom_time.AddMinutes(1)).ToOADate();
chart1.ChartAreas[0].AxisX.Minimum = start;
chart1.ChartAreas[0].AxisX.Maximum = end;
You have to use the ToOADate() methode like the following:
chart1.ChartAreas[0].AxisX.Minimum = zoom_time.AddMinutes(-5).ToOADate();
chart1.ChartAreas[0].AxisX.Maximum = zoom_time.AddMinutes(5).ToOADate();
Edit:
Should have refreshed my page before answering. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With