Using xamarin.ios I need to draw rectangles on my chart based on a series xvalue which is a datetime.
ie from 6pm to 6am i need a rectangle drawn behind my main series.
how would i go about doing this?
Draw Rectangle based on DateTime
Re: Draw Rectangle based on DateTime
Hello,
you could do it by using the OnBeforeDrawSeries event, for example :
you could do it by using the OnBeforeDrawSeries event, for example :
Code: Select all
Chart.BeforeDrawSeries += Chart_BeforeDrawSeries;
private void Chart_BeforeDrawSeries(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
var tmpHour = Utils.GetDateTimeStep(DateTimeSteps.OneHour);
Rectangle rect = Chart.Chart.ChartRect;
g.BackColor = Color.Red;
g.Rectangle(rect.Top + 60, Chart.Axes.Bottom.CalcXPosValue(DateTime.Now.ToOADate() + tmpHour * 3), Chart.Axes.Bottom.CalcXPosValue(DateTime.Now.ToOADate() + tmpHour * 4), rect.Bottom - 60);
}
Pep Jorge
http://support.steema.com
http://support.steema.com
Re: Draw Rectangle based on DateTime
Thanks, but that doesn't stay in the right place when the chart allows panning.
Also, how do you draw more than one rectangle?
I have attached a sample image of what im after (basically indicating nighttime on the chart)
Also, how do you draw more than one rectangle?
I have attached a sample image of what im after (basically indicating nighttime on the chart)
- Attachments
-
- ViewController.cs.zip
- (1.42 KiB) Downloaded 874 times
Re: Draw Rectangle based on DateTime
Hello,
I did a mistake passing the left parameter in the draw rectangle method. The following code works fine even if you pan over the Chart. You can also draw several rectangles (areas).
I did a mistake passing the left parameter in the draw rectangle method. The following code works fine even if you pan over the Chart. You can also draw several rectangles (areas).
Code: Select all
private void Chart_BeforeDrawSeries(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
var tmpHour = Utils.GetDateTimeStep(DateTimeSteps.OneHour);
Rectangle rect = Chart.Chart.ChartRect;
g.BackColor = Color.Red;
g.Rectangle(Chart.Axes.Bottom.CalcXPosValue(DateTime.Now.ToOADate() + tmpHour * 1), rect.Top + 60, Chart.Axes.Bottom.CalcXPosValue(DateTime.Now.ToOADate() + tmpHour * 3), rect.Bottom - 60);
g.BackColor = Color.Yellow;
g.Rectangle(Chart.Axes.Bottom.CalcXPosValue(DateTime.Now.ToOADate() + tmpHour * 4), rect.Top + 60, Chart.Axes.Bottom.CalcXPosValue(DateTime.Now.ToOADate() + tmpHour * 5), rect.Bottom - 60);
}
Pep Jorge
http://support.steema.com
http://support.steema.com
Re: Draw Rectangle based on DateTime
Thanks, that works : )