Question

Updating XYRange ranges at runtime

Posted 4 years ago by Avatar Dan Bryant

I have an application where I'd like to generate XYRange information at runtime for a chart with a line series.  The example shows how to use a hard-coded range, which works fine.  However, if I try to create the range and bind the Minimum/Maximum values, this doesn't work (in this case, I get a range that covers the entire chart and doesn't change even when the properties change.)

            <charts:XYChart.XAxes>
                <charts:XYDoubleAxis x:Name="AxisX" Title="{Binding Series1.XCaption}"
                                     AreLabelsVisible="True" AreMajorTicksVisible="True" Minimum="{Binding MinX}" Maximum="{Binding MaxX}"
                                     TickMajorInterval="{Binding TickIntervalX}">
                    <charts:XYDoubleAxis.Ranges>
                        <charts:XYRange Orientation="Vertical" Minimum="{Binding MinSense1}" Maximum="{Binding MaxSense1}" Background="#A00000FF"/>
                    </charts:XYDoubleAxis.Ranges>
                </charts:XYDoubleAxis>
            </charts:XYChart.XAxes>

 

        private double _minSense1;
        public double MinSense1
        {
            get { return _minSense1; }
            private set { SetProperty("MinSense1", ref _minSense1, value); }
        }

        private double _maxSense1;
        public double MaxSense1
        {
            get { return _maxSense1; }
            private set { SetProperty("MaxSense1", ref _maxSense1, value); }
        }

 (Note that the SetProperty here takes care of implementing the PropertyChanged notification.)  I've verified that these properties are being set and that they are being set to appropriate values for the line being plotted.

I figured there might be an issue with Binding, so I wrote some code-behind instead, like this:

        public void ClearRanges()
        {
            AxisX.Ranges.Clear();
            Chart.Refresh();
        }

        public void AddRange(XYRange range)
        {
            AxisX.Ranges.BeginUpdate();
            AxisX.Ranges.Add(range);
            AxisX.Ranges.EndUpdate();
            Chart.Refresh();
            Chart.InvalidateVisual();
        }

 I've tried various things here (the Refresh, BeginUpdate, EndUpdate and InvalidateVisual calls were all various things I tried adding to get the range to show up.)  I've verified that these methods are being called and that they're being provided with ranges with good values.  With the code behind approach, I don't see any ranges show up at all (unlike the Binding case, where the range covers the whole chart.)

A few other details, in case they are relevant.

1. My data X typically ranges from about 90 - 115, but can vary depending on the data set I'm computing.

2. My lines do sometimes cross back over themselves (I'm plotting a path in X,Y that may have more than one Y value for the same or close to the same X.)  X values are not necessarily evenly spaced.

3. I manually compute the MinX, MaxX and TickIntervalX properties so that I have about 5 tick intervals for my data.  I compute the width of the XYRange so that it takes up 20% of a tick interval.

At this point, I'm not sure what else to try.  I'd really like to get this working, as being able to visualize this transition area on the graph would be very helpful for users of my application.  I'd actually prefer to visualize this as a vertical dashed line (which I might try to accomplish using a striped brush for the region), but right now I'm just trying to get the basic region approach working.

[Modified 4 years ago]


Comments (2)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Dan,

The problem is that the binding is failing on the range for some reason.  It's odd because we're setting up the logical tree to specifically avoid that issue.  I will log a bug for it.

In the meantime, if you put a x:Name on your XYRange object and set the Minimum/Maximum values in code in response to your real property changes (effectively mimicking a binding), then that will work around the problem.


Actipro Software Support
Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Dan,

We have fixed the XYRange property binding bug for the next 2015.1 maintenance release.


Actipro Software Support
Information The latest build of this product (2018.1 build 0670) was released 10 days ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.