Jump to content
Software FX Community

Point presenter


Bober02

Recommended Posts

Hey there,

 

Another quick question. I want to bind a data trigger to PointPresenter (or anything that actually displays point as a dot on the chart). I simply don't know what actually displays a point... I want to know the equivalent of DataGrid's CellValuePresenter.

Link to comment
Share on other sites

I am assuming because of the question that you are referring to a scatter/line/curve chart, note that templating a chart is a little more involved than templating a datagrid because of the different plot styles (bar, line, pie, scatter, etc.) as well as the number of properties these elements support. To change the template used in a marker you would use the following template

<DataTemplate x:Key="MarkerRect">

  <Rectangle x:Name="marker" Width="{Binding Path=Width}" Height="{Binding Path=Height}" Fill="Purple" Stroke="{Binding Path=MarkerStroke}" StrokeThickness="{Binding Path=MarkerStrokeThickness}" Opacity="{Binding Path=MarkerOpacity}"/>

  <DataTemplate.Triggers>

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

  <DataTrigger.Value>

  <sys:Boolean>True</sys:Boolean>

  </DataTrigger.Value>

  <Setter Property="Opacity" Value="0.25" />

  </DataTrigger>

  </DataTemplate.Triggers>

</DataTemplate>

And the following code

chart1.AllSeries.Marker.Template = (DataTemplate) FindResource("MarkerRect");

Note that you can also set the template in XAML but it takes a couple more lines, in the template I changed the Rectangle Fill to Purple so that you can easily check if the template is being applied (it would normally be bound to MarkerFill to honor the Series.Fill API).

This template's data context is a ChartFX class that exposes a property called DataItem that points to the CLR object you passed to ChartFX. This will allow you to change visual attributes based on your own properties.

JuanC

 

Link to comment
Share on other sites

Thanks for reply firstly.

Just to make it clear, if I have a property Highlighted on each DataItem, which is either true or false, should I modify the above in the following way:

Set another data trigger with Path=DataItem.Highlighted and as value = true I will add setter changing Fill="Gold"

in order to get golden markers for all points which have highlighted property set to true or am I going completely wrong direction? Cheers in advance. (Sorry but posting xaml resulted in my code disappearing as forum treats it as xml or sth...)

Link to comment
Share on other sites

Yes, you can use DataItem.YourOwnPropertyGoesHere in triggers, to change rectangle properties you have to use TargetName as follows

<DataTrigger Binding="{Binding Path=DataItem.HasDiscount}">

  <DataTrigger.Value>

  <sys:Boolean>True</sys:Boolean>

  </DataTrigger.Value>

  <Setter TargetName="marker" Property="Fill" Value="Gold" />

</DataTrigger>

JuanC

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.

Guest
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...