in

Software FX Community

Discuss and find help for all Software FX products.

legend and chart color

Last post 05-30-2009 3:19 PM by rudi. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 05-24-2009 2:40 PM

    • rudi
    • Top 100 Contributor
    • Joined on 10-04-2007

    legend and chart color

    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>

  • 05-24-2009 6:29 PM In reply to

    • JuanC
    • Top 10 Contributor
    • Joined on 03-02-2007

    Re: legend and chart color

    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

  • 05-25-2009 5:54 AM In reply to

    • rudi
    • Top 100 Contributor
    • Joined on 10-04-2007

    Re: legend and chart color

    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?

  • 05-25-2009 12:58 PM In reply to

    • JuanC
    • Top 10 Contributor
    • Joined on 03-02-2007

    Re: legend and chart color

    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[i].Fill = brushes[value];
        }

    }

    Regards,

    JuanC

  • 05-30-2009 3:19 PM In reply to

    • rudi
    • Top 100 Contributor
    • Joined on 10-04-2007

    Re: legend and chart color

    Thanks for the detailed feedback.

     

Page 1 of 1 (5 items)
Copyright 2008 Software FX, Inc.