- Home
- Forum
- Xamarin.Android
- Click on graph. Xamarin android
Click on graph. Xamarin android
Hello. In my app I am using BarSeries to display a graph. The code is below. The question is if there is any way to make any Bar of the graph clickable? Thank you very much.
SfChart chart = new SfChart(this);
ViewModel viewModel = new ViewModel();
ViewModel viewModel = new ViewModel();
//Initializing primary axis
CategoryAxis primaryAxis = new CategoryAxis();
chart.Title.Text = "Results untill now";
//primaryAxis.Title.Text = "Values";
chart.PrimaryAxis = primaryAxis;
CategoryAxis primaryAxis = new CategoryAxis();
chart.Title.Text = "Results untill now";
//primaryAxis.Title.Text = "Values";
chart.PrimaryAxis = primaryAxis;
//Initializing secondary Axis
NumericalAxis secondaryAxis = new NumericalAxis();
chart.SecondaryAxis = secondaryAxis;
secondaryAxis.Title.Text = "Values percent(%)";
NumericalAxis secondaryAxis = new NumericalAxis();
chart.SecondaryAxis = secondaryAxis;
secondaryAxis.Title.Text = "Values percent(%)";
BarSeries lineSeries = new BarSeries()
{
ItemsSource = viewModel.Data,
XBindingPath = "Name",
YBindingPath = "Height",
};
lineSeries.DataMarker.ShowLabel = true;
lineSeries.DataMarker.LabelStyle.LabelPosition = DataMarkerLabelPosition.Inner;
lineSeries.DataMarker.LabelStyle.LabelPosition = DataMarkerLabelPosition.Inner;
chart.SecondaryAxis = new NumericalAxis() { Minimum = 0, Maximum = 110 };
chart.SetBackgroundColor(Android.Graphics.Color.Wheat);
chart.Series.Add(lineSeries);
chart.SetBackgroundColor(Android.Graphics.Color.Wheat);
chart.Series.Add(lineSeries);
SIGN IN To post a reply.
1 Reply
DV
Divya Venkatesan
Syncfusion Team
February 26, 2018 12:25 PM UTC
Hi Konstantinos,
Thanks for using Syncfusion products.
You can use the SelectionChanged event of Chart to perform the operations on clicking the bar. Please refer the below code snippets.
Code snippets for enabling data point selection:
|
lineSeries.DataPointSelectionEnabled = true; |
You can refer the below user guide link for more details about data point selection.
Code snippets to hook SelectionChanged event:
|
chart.SelectionChanged += Chart_SelectionChanged; |
Code snippet of SelectionChanged event:
|
private void Chart_SelectionChanged(object sender, SfChart.SelectionChangedEventArgs e)
{
if (e.P1.SelectedDataPointIndex > -1)
{
//you can perform the operation on clicking the bar here
}
} |
You can refer the below user guide link for more details about SelectionChanged event.
We have prepared a sample for this which can be downloaded from the link.
Please let us know, if you need any further assistance on this.
Regards,
Divya Venkatesan
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
KE Konstantinos Evangelidis
- Feb 23, 2018 04:35 PM UTC
- Feb 26, 2018 12:25 PM UTC