This is a migrated thread and some comments may be shown as answers.

Setting Opacity on a multi-LineSeries Chart using a custom Behavior

1 Answer 130 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 16 Apr 2018, 07:13 PM

I created a test application that works like I want it to.  However now that I am trying to implement it the same way into an existing application, the opacity value I am setting is being ignored.  This complexity of this custom control (using a RadCartesianChart) is pretty crazy.  I just can't find out what is causing it to ignore what I am setting.

Attached is what the chart looks like without and with mouse-overing a LineSeries.  The idea is to highlight the LineSeries the trackball is describing.

Below is how I am setting the opacity in a custom behavior.  I have even tried
 - setting the opacity of each series on the RadCartesianChart itself
 - setting the opacity on the style being used for the LineSeries
 - setting up a style trigger to set the opacity value when the IsSelected property is modified in the behavior

Does anyone have an ideas?

01.private static void ChartTrackBallBehavior_TrackInfoUpdated(object sender, TrackBallInfoEventArgs e)
02.{
03.    ChartDataContext context = e.Context;
04. 
05.    DataPointInfo closestDataPointInfo = context.DataPointInfos
06.        .OrderBy(x => Math.Abs(e.Context.TouchLocation.Y - x.DataPoint.LayoutSlot.Y)).FirstOrDefault();
07. 
08.    foreach (DataPointInfo dataPointInfo in context.DataPointInfos)
09.    {
10.        if (dataPointInfo == closestDataPointInfo)
11.        {
12.            if (dataPointInfo?.DataPoint.DataItem is ChartItem chartItem)
13.            {
14.                ChildChartViewModel childChartViewModel = dataPointInfo.Series.Chart.DataContext as ChildChartViewModel;
15. 
16.                string time = chartItem.XValue.ToString(childChartViewModel?.LabelFormat ?? string.Empty);
17.                string value = chartItem.YValue.ToString(childChartViewModel?.VerticalAxis.DataFormatString ?? string.Empty);
18. 
19.                dataPointInfo.DisplayContent = $"({time}, {value})";
20.                dataPointInfo.Series.Opacity = 1;
21.                dataPointInfo.Series.Tag = "Add";
22.            }
23.        }
24.        else
25.        {
26.            dataPointInfo.Series.Opacity = 0.33;
27.            dataPointInfo.Series.Tag = "Remove";
28.        }
29.    }
30. 
31.    e.Context.DataPointInfos.RemoveAll(x => x.Series.Tag.ToString() == "Remove");
32.}

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 18 Apr 2018, 09:30 PM
Hello Kyle,

Without your original implementation (the complex one) I cannot be sure what is going on. However, I can suggest you couple of options. The first one is to extract the chart's set up and all interactions with it from the complex project and send it over in the support ticket that you posted on the same topic. And the second option is to use a different property to fade out the series - for example the Stroke property of the line series. You can apply a color that has its opacity set to 0.33.

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ChartView
Asked by
Kyle
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or