Jump to content
Software FX Community

Bubble Chart


Recommended Posts

Assuming sample data as follows

<XmlDataProvider x:Key="mySampleData" XPath="Products/Product">


  <Products xmlns="">

  <Product Sales="20" Projected="18" Country="USA"/>

  <Product Sales="12" Projected="16" Country="Japan"/>

  <Product Sales="15" Projected="9" Country="Germany"/>

  <Product Sales="28" Projected="29" Country="Brazil"/>




You can do this

<cfx:Chart Gallery="Bubble" x:Name="chart1" Grid.Row="1" ClickCommand="{x:Static cfx:Chart.SelectCommand}" ItemsSource="{Binding Source={StaticResource mySampleData}}">


  <cfx:SeriesAttributes BindingPath="@Sales"/>

  <cfx:SeriesAttributes BindingPath="@Projected"/>






  <Ellipse x:Name="ellipse" Width="{Binding Path=Width}" Height="{Binding Path=Height}" Fill="{Binding Path=Fill}" Stroke="{Binding Path=MarkerStroke}" StrokeThickness="{Binding Path=StrokeThickness}" Opacity="0.5"/>


  <DataTrigger Binding="{Binding Path=Selected}">




  <Setter Property="Opacity" Value="1" TargetName="ellipse" />









  <TextBlock DataContext="{Binding ElementName=chart1, Path=SelectedItem}" Text="{Binding XPath=@Country}" />




Note the following

1) Setting the ClickCommand to be the SelectCommand means we will change the selectedItem property of the chart to point to the data item when the user clicks the marker

2) By default our styles do not show Selected items in a different way so we are templating the bubble chart, setting default transparency to 50% and then setting it to 100% when the item is selected. You can also decide to show the bubble with a different Fill/Border/BorderThicknes

3) We are binding the content of the title to be show the country the user is selecting, you could also bind other pieces of your UI, e.g. showing a panel with multiple details about the selected bubble.

4) Because DataItem is a CLR property but our source is XML the textblock binding is "broken" in two as mixing Path and XPath does not seem to work.

 Hope this helps.



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...