CustomTrackballBehavior trackballBehavior = new CustomTrackballBehavior(this);
trackballBehavior.ActivationMode = ChartTrackballActivationMode.TouchMove;
trackballBehavior.MarkerStyle.ShowMarker = false;
chart.Behaviors.Add(trackballBehavior);
public class CustomTrackballBehavior : ChartTrackballBehavior
{
…..
protected override void OnTouchUp(float valueX, float valueY) => _isActivated = false;
protected override View GetView(ChartSeries series, object data, int index)
{
LinearLayout rootLayout = new LinearLayout(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(120, 70);
rootLayout.Orientation = Orientation.Horizontal;
rootLayout.LayoutParameters = layoutParams;
TextView yLabel = new TextView(context);
yLabel.Gravity = GravityFlags.Center;
yLabel.Text = (data as ChartDataModel).YValue.ToString("C", new CultureInfo("en-GB"));
yLabel.SetTextColor(Color.White);
yLabel.TextSize = 15;
LinearLayout layout = new LinearLayout(context);
LinearLayout.LayoutParams linearlayoutParams = new LinearLayout.LayoutParams(150, 50);
layout.Orientation = Orientation.Vertical;
layout.LayoutParameters = linearlayoutParams;
layout.AddView(yLabel);
rootLayout.AddView(layout);
return rootLayout;
}
protected override void OnLabelsGenerated(List<ChartPointInfo> chartPointsInfo)
{
List<ChartPointInfo> NewchartPointInfos = chartPointsInfo;
ChartPointInfo chartPoint = chartPointsInfo[0];
if (chartPointsInfo.Count < Chart.Series.Count)
foreach (var series in Chart.Series)
{
foreach(var info in chartPointsInfo)
{
if (info.Series != series && chartPointsInfo.Count < Chart.Series.Count)
{
ObservableCollection<ChartDataModel> data = ((series as ChartSeries).ItemsSource) as ObservableCollection<ChartDataModel>;
int index = chartPoint.DataPointIndex > 0 ? chartPoint.DataPointIndex - 1 : chartPoint.DataPointIndex;
ChartDataModel model = data[index];
ChartPointInfo pointInfo = new ChartPointInfo();
pointInfo.Label = model.YValue.ToString();
double yposition = Chart.SecondaryAxis.ValueToPoint(model.YValue);
SetInternalProperty(pointInfo.GetType(), pointInfo, "DataPointIndex", chartPoint.DataPointIndex);
SetInternalProperty(pointInfo.GetType(), pointInfo, "XPosition", chartPoint.XPosition);
SetInternalProperty(pointInfo.GetType(), pointInfo, "YPosition", yposition);
SetInternalProperty(pointInfo.GetType(), pointInfo, "ChartDataPoint", model);
SetInternalProperty(pointInfo.GetType(), pointInfo, "LabelStyle", chartPoint.LabelStyle);
SetInternalProperty(pointInfo.GetType(), pointInfo, "Series", series);
SetInternalProperty(pointInfo.GetType(), pointInfo, "Color", series.Color);
SetInternalProperty(pointInfo.GetType(), pointInfo, "IsVisible", true);
NewchartPointInfos.Add(pointInfo);
break;
}
}
}
base.OnLabelsGenerated(NewchartPointInfos);
}
…….
}
|
DateTimeAxis primaryAxis = new DateTimeAxis();
primaryAxis.LabelStyle.LabelFormat = "MMM yyyy";
primaryAxis.ShowTrackballInfo = true;
primaryAxis.TrackballLabelStyle.LabelFormat = "MMM dd, yyyy";
chart.PrimaryAxis = primaryAxis;
|