We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

ColumnSeries chart color

Hi

I need to implenment a chart that if the value is possitive the bar color should be green, if the value is negative the color should be red, here is the data model:

    class DataModel
    {
        public DateTime DataDate { get; set; }
        public float DataValue{ get; set; }
        public Color Foregroud
        {
            get
            {
                if (DataValue> 0)
                    return Colors.Green;
                else
                    return Colors.Red;
            }
        }
    }

and here is the xaml:

        <Charts:SfChart x:Name="cMainIO" Grid.Row="1">
            <Charts:SfChart.Behaviors>
                <Charts:ChartZoomPanBehavior/>
            </Charts:SfChart.Behaviors>
            <Charts:SfChart.PrimaryAxis>
                <Charts:CategoryAxis x:Name="Primaryx" LabelFormat="MM/dd" />
            </Charts:SfChart.PrimaryAxis>
            <!--SecondaryAxis with range customization-->
            <Charts:SfChart.SecondaryAxis>
                <Charts:NumericalAxis RangePadding="Round" StartRangeFromZero="False" />
            </Charts:SfChart.SecondaryAxis>
            <Charts:ColumnSeries ItemsSource="{Binding}" XBindingPath="DataDate" YBindingPath="DataValue" Interior="{Binding Foregroud, Mode=OneWay}" />
        </Charts:SfChart>

When I run the app the color of bars are still blue,

How to fix it?

1 Reply

RA Rachel A Syncfusion Team July 21, 2015 06:24 AM UTC

Hi William,

Thank you for contacting Syncfusion support.

Query: How to implement a chart that if the value is positive the bar color should be green, if the value is negative the color should be red?

We can achieve your requirement using CustomTemplate property in ColumnSeries which allows customize the series.

Please find the output image as shown below.



We have prepared sample for you reference and please find the sample in the below location.

Sample: ColumnSeriesInterior

Please refer the below documentation for more information.

Link: http://help.syncfusion.com/ug/wpf/Documents/customizeseries.htm

Please let us know if you require any further assistance.

Thanks,
Rachel. A

Loader.
Up arrow icon