setting a constant MaxDataPointValue

Jan 15, 2014 at 2:17 PM
Hi,
Is there any way to set the MaxDataPointValue of a bar chart (or ClusteredBarChart) to constant?
just adding MaxDataPointValue=5 doesn't work. it still calculates the max value based on the values of the series items.

Thanks!
Nov 12, 2014 at 5:28 PM
I am looking for a solution to this problem as well. Any luck with this?
Nov 12, 2014 at 7:55 PM
I fixed this issue by adding a Dependency Property called "IsMaxDataValueFixed" to ChartBase.cs.
        public static readonly DependencyProperty IsMaxDataPointValueFixedProperty =
            DependencyProperty.Register("IsMaxDataPointValueFixed", typeof(bool), typeof(ChartBase), new PropertyMetadata(false));

        public bool IsMaxDataPointValueFixed
        {
            get { return (bool)GetValue(IsMaxDataPointValueFixedProperty); }
            set { SetValue(IsMaxDataPointValueFixedProperty, value); }
        }
Then, in CreateDataPointBindings, I changed the BindingMode to TwoWay:
            var maxDataPointValueBinding = new Binding();
            maxDataPointValueBinding.Source = this;
            maxDataPointValueBinding.Mode = BindingMode.TwoWay;  //Change this from OneWay to TwoWay
            maxDataPointValueBinding.Path = new PropertyPath("MaxDataPointValue");
            BindingOperations.SetBinding(datapoint, DataPoint.MaxDataPointValueProperty, maxDataPointValueBinding);
Then, in RecalcMaxDataPointValue() I short-circuit the execution by adding a check for IsMaxDataPointValueFixed:
        private void RecalcMaxDataPointValue()
        {
            if (IsMaxDataPointValueFixed)
            {
                return;
            }  
            ...
        }
In the XAML of my project:
        <chart:ClusteredColumnChart 
                ...
                MaxDataPointValue="100"
                IsMaxDataPointValueFixed="True">
This change had the desired effect for the Clustered Column Chart in my environment. I haven't tested it with other chart types. When I set the MaxDataPointValue to something lower than the actual max value, the bars stay "maxed-out" on the chart, but display their actual values.

Hope this help anyone who needs it.
Nov 14, 2014 at 9:50 PM
This should really be included into the main source. Well done.