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

Dynamically setting the "MAX" value on the valueAxis the same for two charts

1 Answer 442 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Lisa
Top achievements
Rank 1
Lisa asked on 05 Sep 2013, 08:20 PM
Hi - I would like to set the Max value on the valueAxis for two charts to the same value.  I want to use the max value found, and it won't always be the same or even on the same chart.  The charts sit side-by-side on my page and having the max be different can be misleading for our customers.  Attached is a screen shot showing what I mean.  In this case, I'd want the max to be either 43.36, or better yet rounded up to 50, for both charts, since that's the largest value I have.

Is there a way to do this?  I can of course hard-code a value, but we get quite a range depending on what the users pick to look at.

Thanks

Lisa

1 Answer, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 06 Sep 2013, 10:58 AM
Hi,

I was about to suggest that you use data source aggregates to get the maximum value, but this won't work well as the axis extend beyond that.
There's no public API that will get us the effective axis range, but we can reach to the implementation objects to get this information.

    function createMaster() {
      $("#chartMaster").kendoChart({
        // ...
        dataBound: function() {
          setTimeout(createSlave, 0);
        }
      });
    }

    function createSlave(e) {
      var master = $("#chartMaster").data("kendoChart"),
          max = master._plotArea.valueAxis.range().max;
      
      $("#chartSlave").kendoChart({
        // ...
        valueAxis: {
          max: max
        }
      });
    }


-- Live demo --

The setTimeout is necessary as we don't have an event that fires when the axis range is set. This happens immediately after data binding.
Please keep in mind that relying on implementation details such as _plotArea carries a risk, as they're subject to change. Please test when upgrading.

I hope this helps.

Regards,
T. Tsonev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Charts
Asked by
Lisa
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Share this question
or