我应该在运行时添加 4 个 teechart 控件。我能够将值绑定到 teechart 控件。
问题是,当我滚动父视图时,所有的 teecharts 都消失了。但所有其他控件都是可见的(按钮、文本视图等)。
注意:最初所有控件都是可见的;只有当我滚动时它们才会消失。
void drawRainfallChart()
{
try
{
obj = new csGraphClass();
RainfallGraph[] graphdata = obj.getRainfallData(_cropId.ToString());
if (rainfallChart == null)
rainfallChart = new Steema.TeeChart.TChart(this);
else
{
rainfallChart.RemoveAllViews();
rainfallChart.Dispose();
rainfallChart = new Steema.TeeChart.TChart(this);
}
if (graphdata.Length > 0)
{
rainfallChart.Aspect.View3D = false;
rainfallChart.Chart.Invalidate();
Steema.TeeChart.Styles.Line rline = new Steema.TeeChart.Styles.Line();
Steema.TeeChart.Styles.Line rCrtdayline = new Steema.TeeChart.Styles.Line();
rainfallChart.Series.Add(rline);
rainfallChart.Series.Add(rCrtdayline);
DateTime currentdate = SyncProcess.CalculatedDatetime();
double dc = 0;
foreach (RainfallGraph item in graphdata)
{
dc += Convert.ToDouble(item.yValue);
rline.Add(Convert.ToDateTime(item.xValue), dc);
if (item.xValue == currentdate.ToString("yyyy-MM-dd"))
{
rCrtdayline.Add(Convert.ToDateTime(item.xValue), 0);
rCrtdayline.Add(Convert.ToDateTime(item.xValue), Convert.ToDouble(item.yValue));
}
}
rline.Title = "Rainfall";
rCrtdayline.Title = "Crop Day";
rline.Pointer.Visible = true;
rline.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.Circle;
rline.Chart.Axes.Left.SetMinMax(0, Convert.ToDouble(dc + 5));
var varMinDate = graphdata.Min(s => s.xValue);
var varMaxDate = graphdata.Max(s => s.xValue);
DateTime minDate = Convert.ToDateTime(varMinDate).AddDays(-1);
DateTime maxDate = Convert.ToDateTime(varMaxDate).AddDays(1);
rline.Chart.Axes.Bottom.SetMinMax(minDate, maxDate);
rainfallChart.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneDay);
rainfallChart.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy";
rainfallChart.Footer.Font.Size = 25;
rainfallChart.Legend.Font.Size = 25;
rainfallChart.Header.Font.Size = 25;
rainfallChart.Axes.Bottom.Labels.Font.Size = 18;
rainfallChart.Axes.Left.Labels.Font.Size = 15;
rainfallChart.Legend.Transparent = true;
rainfallChart.Header.Visible = true;
rainfallChart.Axes.Bottom.Grid.Visible = false;
rainfallChart.Header.Text = "Rain fall";
rainfallChart.Legend.Visible = true;
rainfallChart.Axes.Left.Grid.DrawEvery = 1;
rainfallChart.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom;
rainfallChart.Panning.Allow = Steema.TeeChart.ScrollModes.None;
rainfallChart.Panning.Allow = Steema.TeeChart.ScrollModes.None;
rainfallChart.Zoom.Style = Steema.TeeChart.ZoomStyles.Classic;
rainfallChart.Zoom.Allow = false;
rainfallChart.Panning.Allow = ScrollModes.None;
rainfallChart.SetPadding(0, 50, 0, 50);
Android.Widget.LinearLayout.LayoutParams layoutParams = new Android.Widget.LinearLayout.LayoutParams(graphheight, graphwidth);
layoutParams.TopMargin = 100;
layoutParams.BottomMargin = 100;
rainfallChart.ScrollBarStyle = ScrollbarStyles.InsideOverlay;
rainfallChart.SetScrollContainer(false);
srcgraph.AddView(rainfallChart, layoutParams);
}
}
catch (Exception ex)
{
ErrorHandling.ErrorEntry(ex.Message.ToString(), "TodayGraphViewController - drawRainfallChart");
}
}