Hi, I was trying to create a line chart and I couldn't.
The chart in the SfDateTimeRangeNavigator works fine but the chart itself not showing data, can you tell me what's wrong?
XML Code :
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Com.Syncfusion.Charts.SfChart
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="@+id/Chart" />
<Com.Syncfusion.Rangenavigator.SfDateTimeRangeNavigator
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/ChartDateNav" />
</LinearLayout>
SfChart Chart = FindViewById<SfChart>(Resource.Id.Chart);
SfChart NavChart = new SfChart(this);
SfDateTimeRangeNavigator ChartDateNav = FindViewById<SfDateTimeRangeNavigator>(Resource.Id.ChartDateNav);
DateTimeAxis XAxis = new DateTimeAxis();
XAxis.LabelCreated += (sender, e) => {
e.AxisLabel.LabelContent = JDateTime.JDateNTime(DateTime.Parse((string)e.AxisLabel.LabelContent));
};
NumericalAxis YAxis = new NumericalAxis();
ObservableCollection<ChartData> Data = new ObservableCollection<ChartData>() {
new ChartData { Date = DateTime.Now.AddDays(-10), Price = 180000 },
new ChartData { Date = DateTime.Now.AddDays(-8), Price = 170000 },
new ChartData { Date = DateTime.Now.AddDays(-4), Price = 190000 },
new ChartData { Date = DateTime.Now.AddDays(-1), Price = 180000 }
};
LineSeries LSeries = new LineSeries() {
ItemsSource = Data,
XBindingPath = "Date",
YBindingPath = "Price",
Label = "First Product",
TooltipEnabled = true,
Color = Color.Green,
SelectedDataPointColor = Color.DarkGreen
};
ChartTrackballBehavior TrackballBehavior = new ChartTrackballBehavior {
ShowLabel = true,
ShowLine = true
};
Chart.PrimaryAxis = XAxis;
Chart.SecondaryAxis = YAxis;
Chart.Series.Add(LSeries);
Chart.Behaviors.Add(TrackballBehavior);
DateTimeAxis NavXAxis = new DateTimeAxis() {
Visibility = Visibility.Gone,
ShowMajorGridLines = false,
ShowMinorGridLines = false
};
NumericalAxis NavYAxis = new NumericalAxis() {
Visibility = Visibility.Gone,
ShowMajorGridLines = false,
ShowMinorGridLines = false
};
ObservableCollection<ChartData> NavData = new ObservableCollection<ChartData>() {
new ChartData { Date = DateTime.Now.AddDays(-10), Price = 180000 },
new ChartData { Date = DateTime.Now.AddDays(-8), Price = 170000 },
new ChartData { Date = DateTime.Now.AddDays(-4), Price = 190000 },
new ChartData { Date = DateTime.Now.AddDays(-1), Price = 180000 }
};
LineSeries NavLSeries = new LineSeries() {
ItemsSource = NavData,
XBindingPath = "Date",
YBindingPath = "Price",
Color = Color.Green,
};
NavChart.PrimaryAxis = NavXAxis;
NavChart.SecondaryAxis = NavYAxis;
NavChart.Series.Add(NavLSeries);
NavChart.Legend.Visibility = Visibility.Gone;
var Min = DateTime.Now.AddDays(-11);
var Max = DateTime.Now;
ChartDateNav.Minimum = new GregorianCalendar(Min.Year, Min.Month, Min.Day, Min.Hour, Min.Minute, Min.Second).Time;
ChartDateNav.Maximum = new GregorianCalendar(Max.Year, Max.Month, Max.Day, Max.Hour, Max.Minute, Max.Second).Time;
ChartDateNav.RangeChanged += (sender, e) => {
XAxis.Minimum = e.ViewRangeStart;
XAxis.Maximum = e.ViewRangeEnd;
};
ChartDateNav.Content = NavChart;
ChartDateNav.MajorScaleStyle.ShowGridLines = false;
ChartDateNav.MinorScaleStyle.ShowGridLines = false;