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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to color the chart elements in run-time?

Platform: WPF |
Control: Chart |
Published Date: April 30, 2011 |
Last Revised Date: March 15, 2018


Essential chart allows you to color every part of the chart, such as series, labels, axis, etc., in run-time. The following code shows how a chart series, labels, axis, etc., can be colored when these elements are hit by mouse.


//Events raised on series mouse click - Sets series interior

private void ChartSeries_MouseClick(object sender, ChartMouseEventArgs e)


area.Series[0].Interior = Brushes.Green;

area.Series[1].Interior = Brushes.Blue;

ChartSeries series1 = sender as ChartSeries;

series1.Interior = Brushes.Orange;



//Events raised on axis mouse down - Sets axis linestroke and label color

private void ChartAxis_MouseDown(object sender, MouseButtonEventArgs e)


ChartAxis axis = sender as ChartAxis;

HitTestResult result = VisualTreeHelper.HitTest(area, e.GetPosition(area));

if (result != null)


FrameworkElement hitElement = result.VisualHit as FrameworkElement;

//Colors the Chart Axis labels

if (hitElement.GetType() == typeof(TextBlock))


TextBlock txtBlk = hitElement as TextBlock;

txtBlk.Foreground = Brushes.Orange;


//Colors the Axis linestroke

if (hitElement.GetType() == typeof(ChartCartesianAxisElement))


axis.LineStroke.Brush = Brushes.Orange;




Refer to the attached sample, which illustrates this feature.

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon