Jump to content
Software FX Community

Recommended Posts

Posted

Hi,

 I'm having a disconnect between the color of my legend items and the colors in the chart when using conditional attributes. Is there something I need to do in additiona to have the legend follow the chart colors?

 

The code I have for my chart is:

  <ContentControl x:Key="ContentControlChartWorkflowRunStatus">

  <ChartFX:Chart Name="chartWorkflowRunStatus" Gallery="Pie">

  <ChartFX:Chart.ItemsSource>

  <Binding Source="{StaticResource TheViewSource}"/>

  </ChartFX:Chart.ItemsSource>

  <ChartFX:Chart.DataTransforms>

  <ChartFXData:CrosstabTransform RowPath="RunStatusCode"/>

  </ChartFX:Chart.DataTransforms>

  <ChartFX:Chart.Titles>

  <ChartFX:Title>Run Status</ChartFX:Title>

  </ChartFX:Chart.Titles>

  <ChartFX:Chart.ConditionalAttributes>

  <ChartFX:ConditionalAttributes Fill="Green">

  <ChartFX:ConditionalAttributes.Condition>

  <ChartFX:RangeCondition From="1" To="1" BindingPath="RunStatusCode"/>

  </ChartFX:ConditionalAttributes.Condition>

  </ChartFX:ConditionalAttributes>

  <ChartFX:ConditionalAttributes Fill="WhiteSmoke">

  <ChartFX:ConditionalAttributes.Condition>

  <ChartFX:RangeCondition From="2" To="2" BindingPath="RunStatusCode"/>

  </ChartFX:ConditionalAttributes.Condition>

  </ChartFX:ConditionalAttributes>

  <ChartFX:ConditionalAttributes Fill="Red">

  <ChartFX:ConditionalAttributes.Condition>

  <ChartFX:RangeCondition From="3" To="3" BindingPath="RunStatusCode"/>

  </ChartFX:ConditionalAttributes.Condition>

  </ChartFX:ConditionalAttributes>

  <ChartFX:ConditionalAttributes Fill="OrangeRed">

  <ChartFX:ConditionalAttributes.Condition>

  <ChartFX:RangeCondition From="4" To="4" BindingPath="RunStatusCode"/>

  </ChartFX:ConditionalAttributes.Condition>

  </ChartFX:ConditionalAttributes>

  <ChartFX:ConditionalAttributes Fill="BurlyWood">

  <ChartFX:ConditionalAttributes.Condition>

  <ChartFX:RangeCondition From="5" To="5" BindingPath="RunStatusCode"/>

  </ChartFX:ConditionalAttributes.Condition>

  </ChartFX:ConditionalAttributes>

  <ChartFX:ConditionalAttributes Fill="BlueViolet">

  <ChartFX:ConditionalAttributes.Condition>

  <ChartFX:RangeCondition From="6" To="6" BindingPath="RunStatusCode"/>

  </ChartFX:ConditionalAttributes.Condition>

  </ChartFX:ConditionalAttributes>

  <ChartFX:ConditionalAttributes Fill="Black">

  <ChartFX:ConditionalAttributes.Condition>

  <ChartFX:RangeCondition From="15" To="15" BindingPath="RunStatusCode"/>

  </ChartFX:ConditionalAttributes.Condition>

  </ChartFX:ConditionalAttributes>

  </ChartFX:Chart.ConditionalAttributes>

  </ChartFX:Chart>

  </ContentControl>

post-5660-13922409658132_thumb.png

Posted

ConditionalAttributes will appear in the legend if they have their content property set, but they are intended to be used for special values e.g. in a line chart when you want to highlight points that have special meaning, not to change the color for all your pie slices.

Pie charts will use attributes from the Points collection, so I would recommend you remove the conditional attributes and replace it with the following

<cfx:Chart.Points>   <cfx:PointAttributes Fill="Red"/>   <cfx:PointAttributes Fill="Blue"/>   <cfx:PointAttributes Fill="Green"/>   <cfx:PointAttributes Fill="Yellow"/></cfx:Chart.Points>

Regards,

JuanC

Posted

Hi JuanC,

 The reason I'm using the conditional attributes is that the color depends on the value. I want 1 always to be green, 3 always to be red, etc. I don't know however if all values are always there. There might be only 3, which should turn the whole pie chart red, and not green because that's the first Pointattribute in the list.

Can I use pointvalues to ensure the mapping between color and Value?

Posted

I apologize for the confusion, if you want the color depending on the value, then conditional attributes and not Points is the right API (if you want to do it in XAML).

Unfortunately we do not apply conditionalattributes to the Point collection, we will consider adding this functionality to future versions but in the meantime the only way to achieve color per values and get the correct information in the legend would be to attach to the Chart DataBound event and then loop through the data

private void OnDataBound (object sender, EventArgs e)

{

 

Brush[] brushes = new Brush[] {

 

Brushes.Black, // 0

 

Brushes.Red, // 1

 

Brushes.Green, // 2

 

Brushes.Blue, // 3

 

Brushes.Yellow, // 4

 

Brushes.Brown, // 5

 

};

  for (int i = 0; i < chart1.Data.Points; i++) {

 

int value = (int) chart1.Data[0,i];

 

if (value < brushes.Length)

  chart1.Points.Fill = brushes[value];

  }

}

Regards,

JuanC

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