Jump to content
Software FX Community

How to Create a Legend for Conditional Attribute Colors


DSimons
 Share

Recommended Posts

Hi,

I am currently using a bullet chart with multiple instances of the following data structure:

<RechargeInfo   START_TIME="11/1/2009  6:00:00 PM"     FINISH_TIME="11/1/2009  6:45:00 PM"   BATT_START=".10"   BATT_FINISH=".90"   COUPLING="1.77777777777778"   />

I am using the chart to compare the BATT_START and BATT_FINISH values in the data structure above. 

I have successfully used the Conditional Attributes feature to color the fill of the graph based on specific rules in the XAML code with the following code:

<cfx:Chart.ConditionalAttributes>
  <cfx:ConditionalAttributes  Fill="Red">
  <cfx:ConditionalAttributes.Condition>
  <cfx:RangeCondition From="0.0" To="0.5" BindingPath="@COUPLING"/>
  </cfx:ConditionalAttributes.Condition>
  </cfx:ConditionalAttributes>
  <cfx:ConditionalAttributes Fill="Yellow">
  <cfx:ConditionalAttributes.Condition>
  <cfx:RangeCondition From="0.5" To="1.25" BindingPath="@COUPLING"/>
  </cfx:ConditionalAttributes.Condition>
  </cfx:ConditionalAttributes>
  <cfx:ConditionalAttributes Fill="Green">
  <cfx:ConditionalAttributes.Condition>
  <cfx:RangeCondition From="1.25" BindingPath="@COUPLING"/>
  </cfx:ConditionalAttributes.Condition>
  </cfx:ConditionalAttributes>
  </cfx:Chart.ConditionalAttributes>

I would like to have a legend box which can display the meaning of the coloring of these conditional attributes, but I am not sure how to do this with the current LegendBox. Per another Forum post here I am not sure this is possible using the LegendBox. Can you help me to display a legend to the user for these conditional attributes, and if necessary, suggest a replacement for the conditional attributes?

Link to comment
Share on other sites

This looks like it has worked quite well!

I added Content properties and now these conditional attributes are showing up in the Legend. However, this raises a follow-up question: how can I remove the the first two series in the legend, so I am only showing the colors ConditionalAttributes? 

Directions for how to do this appear to be in the ChartFX Resource Center under "LegendItemAttributes class", but I think there is an error in this documentation. The code suggested is:

 

LegendItemAttributes item = new LegendItemAttributes();chart1.LegendBox.ItemAttributes[chart1.Series[0]] = item;item.Visible = false;

 

I am doing the following: 

1) I am declaring the Series Attributes in WPF like this: 

<cfx:Chart.Series>   <cfx:SeriesAttributesCollection>   <cfx:SeriesAttributes BindingPath="@BATT_FINISH" Content="Battery Finish" />   <cfx:SeriesAttributes BindingPath="@BATT_START" Content="Battery Start" Volume="60" Opacity=".75"/>   </cfx:SeriesAttributesCollection>   </cfx:Chart.Series>

In the C# constructor, I try to access the series:

          LegendItemAttributes item = new LegendItemAttributes();   _batteryRechargeChart.LegendBox.ItemAttributes[_batteryRechargeChart.Series[0]] = item;

HoweverI receive the erorr on _batteryRechargeChart of:

Error   2   Argument '1': cannot convert from 'ChartFX.WPF.SeriesAttributes' to 'ChartFX.WPF.Internal.ILegendItemGenerator'

 

Additionally, I believe the 3rd line of your documentation should be corrected to:

item.Visibility = System.Windows.Visibility.Hidden;

Link to comment
Share on other sites

Forgot to ask my other question:

I would also like to have these ConditionalAttributes only affect one of the two data series values (BATT_FINISH, not BATT_START). I thought I could do this by using the AffectedSeries property like this:

<cfx:ConditionalAttributes Fill="Red" Content="Poor Coupling" AffectedSeries="1">   <cfx:ConditionalAttributes.Condition>   <cfx:RangeCondition From="0.0" To="0.5" BindingPath="@COUPLING"/>   </cfx:ConditionalAttributes.Condition>   </cfx:ConditionalAttributes>

Unfortunately if I set this AffectedSeries property the coloring no longer works for any of the series. How can I ensure that I only color one of the two data series?

Link to comment
Share on other sites

Actually the code should be

chart1.LegendBox.ItemAttributes[chart1.Series].Visibility = Visibility.Hidden;

Note that the index used for the ItemAttributes property is the series collection (not one of the series), if you are using our most recent service pack you can also do it in XAML as follows

<cfx:Chart.LegendBox>

  <cfx:LegendBox>

  <cfx:LegendBox.ItemAttributes>

  <cfx:LegendItemAttributes cfx:LegendItemAttributes.LegendItemType="Series" Visibility="Hidden"/>

  </cfx:LegendBox.ItemAttributes>

  </cfx:LegendBox>

</cfx:Chart.LegendBox>

JuanC

Link to comment
Share on other sites

You can get our most recent service pack here, we will soon be uploading a new service pack build but even though the XAML approach will work on that build we recently discovered and fixed an issue related to ConditionalAttributes when using BindingPath and AffectedSeries simultaneously (because of your post on this thread).

To fix this issue you can download our most recent hotfix here, note that service pack builds go through more testing than hotfixes but we can release hotfixes as soon as issues are corrected.

In both cases you need to run IE as administrator if your machine has UAC enabled.

JuanC

Link to comment
Share on other sites

  Juan,

Thanks for your reply! Does that imply that
A) I discovered a small bug with the AffectedSeries in my post here?
B) That you have  been able to fix the  bug and posted a hotfix as described in your post?  

If I have misunderstood this, could you post a quick reply addressing my question in the same post above ? Thanks again for your help, I think this will resolve all of my issues for thread when this is addressed or confirmed.

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.

 Share

×
×
  • Create New...