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

Using nullable decimal fields to optionally set ValueAxis Min and Max

2 Answers 67 Views
Chart
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 31 Mar 2016, 04:16 PM

I'm hoping this is possible as we are allowing end users to optionally set the min and max value axis amounts. I would like the chart itself to set either or both the Min or Max if the decimal? field is null. Right now I'm using the following code snippet:

.ValueAxis(x => x.Numeric()
        .Min(Model.YAxisRangeMin.GetValueOrDefault())
        .Max(Model.YAxisRangeMax.GetValueOrDefault()))

 This works fine if the decimal? fields have values, but if they are null, the defaults are set to 0, which is not good.

Problem is, I really only want to set a Min/Max value if it is not null. Any ideas how to do that within the control? Am I going to have to calculate the max on the server and use that as the default for the YAxisRangeMax if null? Min as 0 is fine.

Thanks!

2 Answers, 1 is accepted

Sort by
0
James
Top achievements
Rank 1
answered on 01 Apr 2016, 06:55 PM

For now, I just stuffed the max Value into a field and am using that to set the default Max value (i.e., Max(Model.YAxisRangeMax.GetValueOrDefault(Model.YAxisMaxDefault)), which seems to be working (I set the max to 1.1 X the actual max value). Since the end user can also select different chart types, I added another property for StackedArea YAxisMax (3 x max). Let me know if there is a better way.

 

Thanks!

0
Accepted
Daniel
Telerik team
answered on 04 Apr 2016, 09:24 AM
Hello,

You could check if the value is not null before setting the option to the axis e.g.
.ValueAxis(axis =>
    {
        var numericAxis = axis.Numeric();
        if (Model.YAxisRangeMin.HasValue)
        {
            numericAxis.Min(Model.YAxisRangeMin.Value);
        }
        if (Model.YAxisRangeMax.HasValue)
        {
            numericAxis.Max(Model.YAxisRangeMax.Value);
        }
    }
)


Regards,
Daniel
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Chart
Asked by
James
Top achievements
Rank 1
Answers by
James
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or