Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
150128 | Dec 21,2019 02:41 PM UTC | Jan 7,2020 07:09 AM UTC | Xamarin.Forms | 1 |
![]() |
Tags: SfChart |
public class PieChartExt : SfChart
{
public static readonly BindableProperty ItemsSourceProperty =
BindableProperty.Create("ItemsSource", typeof(object), typeof(PieChartExt), null, BindingMode.Default, null, OnItemsSourceChanged);
public static readonly BindableProperty XBindingPathProperty =
BindableProperty.Create("XBindingPath", typeof(string), typeof(PieChartExt), "XValue", BindingMode.Default, null);
public static readonly BindableProperty YBindingPathProperty =
BindableProperty.Create(nameof(YBindingPath), typeof(string), typeof(PieChartExt), "YValue", BindingMode.Default, null);
public object ItemsSource
{
get { return (object)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
public string XBindingPath
{
get { return (string)GetValue(XBindingPathProperty); }
set { SetValue(XBindingPathProperty, value); }
}
public string YBindingPath
{
get { return (string)GetValue(YBindingPathProperty); }
set { SetValue(YBindingPathProperty, value); }
}
private static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue)
{
(bindable as PieChartExt).GenerateSeries(newValue);
}
private void GenerateSeries(object newValue)
{
if (ItemsSource != null)
{
var commonItemsSource = (ItemsSource as IEnumerable).GetEnumerator();
if (newValue is INotifyCollectionChanged)
(newValue as INotifyCollectionChanged).CollectionChanged += DataPoint_CollectionChanged;
while (commonItemsSource.MoveNext())
{
CreateSeries(commonItemsSource.Current);
}
}
}
…
} |
<local:PieChartExt x:Name="Chart" ItemsSource="{Binding Data}" XBindingPath="Component" YBindingPath="Price" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<chart:SfChart.Title>
<chart:ChartTitle Text="A Linear PieChart" />
</chart:SfChart.Title>
<chart:SfChart.BindingContext>
<local:ViewModel x:Name="viewModel" />
</chart:SfChart.BindingContext>
<chart:SfChart.PrimaryAxis>
<chart:CategoryAxis IsVisible="False" ShowMajorGridLines="False" >
</chart:CategoryAxis>
</chart:SfChart.PrimaryAxis>
<chart:SfChart.SecondaryAxis>
<chart:NumericalAxis IsVisible="False" ShowMajorGridLines="False">
</chart:NumericalAxis>
</chart:SfChart.SecondaryAxis>
<chart:SfChart.ColorModel>
<chart:ChartColorModel Palette="Natural"/>
</chart:SfChart.ColorModel>
</local:PieChartExt> |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.