- Home
- Forum
- Xamarin.Android
- Update sfchart values
Update sfchart values
Hello. I am trying to update the values of my graphs but nothing changing. I am setting the graph in this method and after that I am calling this method with different values. And I am recalling the method to update the values I am doing this.
new_vit_graph = view.FindViewById(Resource.Id.graph) as SfChart;
new_vit_graph = new SfChart(Activity);
new_vit_graph.RemoveAllViews();
vitGraphNew(x1, x2);
vitGraphNew(x1, x2);
private void vitGraphNew(TimeSpan x1, TimeSpan x2)
{
Console.WriteLine("vitGraphNew");
double q1 = x1.TotalMinutes;
double q2 = x2.TotalMinutes;
{
Console.WriteLine("vitGraphNew");
double q1 = x1.TotalMinutes;
double q2 = x2.TotalMinutes;
vitTime.Text = (x2.ToString(@"hh\:mm"));
var r = (100 * q2) / q1;
Console.WriteLine("rrr " + r);
Console.WriteLine("rrr " + r);
new_vit_graph.SetBackgroundColor(Color.White);
//Initializing primary axis
CategoryAxis primaryAxis = new CategoryAxis();
new_vit_graph.PrimaryAxis = primaryAxis;
CategoryAxis primaryAxis = new CategoryAxis();
new_vit_graph.PrimaryAxis = primaryAxis;
//Initializing secondary Axis
NumericalAxis secondaryAxis = new NumericalAxis();
secondaryAxis.Maximum = 100;
new_vit_graph.SecondaryAxis = secondaryAxis;
NumericalAxis secondaryAxis = new NumericalAxis();
secondaryAxis.Maximum = 100;
new_vit_graph.SecondaryAxis = secondaryAxis;
vitDdata = new ObservableCollection<Model>();
vitDdata.Add(new Model("David", r));
vitDdata.Add(new Model("David", r));
new_vit_graph.ColorModel.ColorPalette = ChartColorPalette.Custom;
ChartGradientColor gradientColor = new ChartGradientColor() { StartPoint = new PointF(0.5f, 1), EndPoint = new PointF(0.5f, 0) };
ChartGradientStop stop1 = new ChartGradientStop() { Color = Color.ParseColor("#c4ecff"), Offset = 0 };
ChartGradientStop stop2 = new ChartGradientStop() { Color = Color.ParseColor("#086eb6"), Offset = 1 };
gradientColor.GradientStops.Add(stop1);
gradientColor.GradientStops.Add(stop2);
ChartGradientStop stop1 = new ChartGradientStop() { Color = Color.ParseColor("#c4ecff"), Offset = 0 };
ChartGradientStop stop2 = new ChartGradientStop() { Color = Color.ParseColor("#086eb6"), Offset = 1 };
gradientColor.GradientStops.Add(stop1);
gradientColor.GradientStops.Add(stop2);
ChartGradientColorCollection gradientColors = new ChartGradientColorCollection()
{
gradientColor
};
{
gradientColor
};
ChartGradientColor secondGradient = new ChartGradientColor() { StartPoint = new PointF(0.5f, 1), EndPoint = new PointF(0.5f, 0) };
ChartGradientStop secondStop1 = new ChartGradientStop() { Color = Color.ParseColor("#1ac4ecff"), Offset = 0 };
ChartGradientStop secondStop2 = new ChartGradientStop() { Color = Color.ParseColor("#1a086eb6"), Offset = 1 };
secondGradient.GradientStops.Add(secondStop1);
secondGradient.GradientStops.Add(secondStop2);
ChartGradientColorCollection secondGradientColors = new ChartGradientColorCollection()
{
secondGradient
};
{
secondGradient
};
new_vit_graph.ColorModel.CustomGradientColors = gradientColors;
//Initializing column series
StackingColumn100Series vitSeries = new StackingColumn100Series();
vitSeries.ItemsSource = vitDdata;
vitSeries.Label = (x2.ToString(@"hh\:mm"));
vitSeries.XBindingPath = "XValue";
vitSeries.YBindingPath = "YValue";
vitSeries.DataMarker.ShowLabel = false;
//vitSeries.ColorModel.CustomGradientColors = gradientColors;
vitSeries.TooltipEnabled = false;
vitSeries.Width = 1;
vitSeries.EnableAnimation = true;
vitSeries.AnimationDuration = 1;
StackingColumn100Series vitSeries = new StackingColumn100Series();
vitSeries.ItemsSource = vitDdata;
vitSeries.Label = (x2.ToString(@"hh\:mm"));
vitSeries.XBindingPath = "XValue";
vitSeries.YBindingPath = "YValue";
vitSeries.DataMarker.ShowLabel = false;
//vitSeries.ColorModel.CustomGradientColors = gradientColors;
vitSeries.TooltipEnabled = false;
vitSeries.Width = 1;
vitSeries.EnableAnimation = true;
vitSeries.AnimationDuration = 1;
new_vit_graph.SideBySideSeriesPlacement = false;
new_vit_graph.PrimaryAxis.ShowMajorGridLines = false;
new_vit_graph.SecondaryAxis.ShowMinorGridLines = false;
new_vit_graph.SecondaryAxis.ShowMajorGridLines = false;
new_vit_graph.PrimaryAxis.Visibility = Visibility.Gone;
new_vit_graph.SecondaryAxis.Visibility = Visibility.Gone;
new_vit_graph.Legend.Visibility = Visibility.Gone;
new_vit_graph.Legend.IconVisibility = Visibility.Gone;
new_vit_graph.PrimaryAxis.ShowMajorGridLines = false;
new_vit_graph.SecondaryAxis.ShowMinorGridLines = false;
new_vit_graph.SecondaryAxis.ShowMajorGridLines = false;
new_vit_graph.PrimaryAxis.Visibility = Visibility.Gone;
new_vit_graph.SecondaryAxis.Visibility = Visibility.Gone;
new_vit_graph.Legend.Visibility = Visibility.Gone;
new_vit_graph.Legend.IconVisibility = Visibility.Gone;
new_vit_graph.Series.Add(vitSeries);
vitDdata1 = new ObservableCollection<Model>();
vitDdata1.Add(new Model("David", 100 - r));
vitDdata1.Add(new Model("David", 100 - r));
StackingColumn100Series vitSeries1 = new StackingColumn100Series();
vitSeries1.ItemsSource = vitDdata1;
vitSeries1.XBindingPath = "XValue";
vitSeries1.YBindingPath = "YValue";
vitSeries1.DataMarker.ShowLabel = false;
vitSeries1.TooltipEnabled = false;
vitSeries1.Width = 1;
vitSeries1.ColorModel.ColorPalette = ChartColorPalette.Custom;
vitSeries1.ColorModel.CustomGradientColors = secondGradientColors;
vitSeries1.EnableAnimation = true;
vitSeries1.AnimationDuration = 1;
new_vit_graph.Series.Add(vitSeries1);
vitSeries1.ItemsSource = vitDdata1;
vitSeries1.XBindingPath = "XValue";
vitSeries1.YBindingPath = "YValue";
vitSeries1.DataMarker.ShowLabel = false;
vitSeries1.TooltipEnabled = false;
vitSeries1.Width = 1;
vitSeries1.ColorModel.ColorPalette = ChartColorPalette.Custom;
vitSeries1.ColorModel.CustomGradientColors = secondGradientColors;
vitSeries1.EnableAnimation = true;
vitSeries1.AnimationDuration = 1;
new_vit_graph.Series.Add(vitSeries1);
Console.WriteLine("vitGraphNewFinish");
}
}
SIGN IN To post a reply.
3 Replies
DV
Divya Venkatesan
Syncfusion Team
June 7, 2018 09:06 AM UTC
Hi Konstantinos,
Thanks for contacting Syncfusion support.
We have prepared a sample based on your code snippets. On removing “new_vit_graph.RemoveAllViews();”, the chart updates properly. If your requirement is to clear the series and update new series, please use the below code snippet to clear the series.
Code snippet[C#]:
|
new_vit_graph.Series.Clear(); |
We have attached the sample for your reference which can be downloaded from the following link.
Please let us know if you need any further assistance.
Regards,
Divya Venkatesan
KE
Konstantinos Evangelidis
June 12, 2018 10:54 AM UTC
Thank you very much for your answer. Working very nice.
DV
Divya Venkatesan
Syncfusion Team
June 13, 2018 05:09 AM UTC
Hi Konstantinos,
Thanks for the update. We are glad to know that the given solution works.
Please let us know if you need any further assistance.
Regards,
Divya Venkatesan
Thanks for the update. We are glad to know that the given solution works.
Please let us know if you need any further assistance.
Regards,
Divya Venkatesan
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
KE Konstantinos Evangelidis
- Jun 6, 2018 04:58 PM UTC
- Jun 13, 2018 05:09 AM UTC