Setting Selection Properties

You can set how chart items are selected, the appearance of selected chart elements, and the appearance of the labels on the selected items.

To set selection properties, use the following XAML to declare the chart:

<Grid.Resources>

<Style x:Key="selected" TargetType="c1:PlotElement">
<Setter Property="Fill" Value="Red" />
</Style>
<DataTemplate x:Key="label">
<TextBlock Text="{Binding}"/>
</DataTemplate>

</Grid.Resources>

<c1:C1Chart Name="chart">
<c1:C1Chart.Data>
<c1:ChartData SelectionAction="MouseDown">
<c1:DataSeries ValueBinding="{Binding Price}"
SelectedItemStyle="{StaticResource selected}"
SelectedItemLabelTemplate="{StaticResource label}"/>
</c1:ChartData>
</c1:C1Chart.Data>
</c1:C1Chart>

 

Then use the following code to create the sample data:

// create sample data
var items = new ObservableCollection<Product>();
for (int i = 0; i < 5; i++)
items.Add(new Product() { Name = "Product " + i, Price = i });
var collectionView = new PagedCollectionView(items);

// set data source
chart.Data.ItemsSource = collectionView;

 

And this code to set the product class:

public class Product
{
public string Name { get; set; }
public double Price { get; set; }
}


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.