Articles in this section
Category / Section

How to color the chart elements in run-time?

1 min read

 

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.

C#

//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;

}

C#

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

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied