How to access charts (chartArea) width to calculate Labels.Step(X)

3 posts, 1 answers
  1. Dirk
    Dirk avatar
    27 posts
    Member since:
    Aug 2013

    Posted 02 Sep 2013 Link to this post

    Hello,

    I've a stacked area chart, that is filled with dynamic data via JSON. The chart shows data according to start and end date, which the user selects from two datepickers.
    On the category axis I try to put as much labels (rotated by -90° date values) as possible without mixing labels.
    To calculate the appropriate Labels.Step() I need to know two things
    1. number of values on category axis (wich I know)
    2.) the current width of the chart or the chart area (which I don't know)
    to calculate - or better estimate - the max number of labels

    I found the width in the svg property of the chart, but don't know how to extract from that text.

    Is there another way to determine the charts width or a totally different approach to estimate max number of labels on the category axis?

    Thanks in advance
    Dirk
  2. Answer
    T. Tsonev
    Admin
    T. Tsonev avatar
    2831 posts

    Posted 04 Sep 2013 Link to this post

    Hi,

    I think we can use the dataBound event, similarly to my suggestion in your other forum post.

    dataBound: function() {
        // Category axis width _before_ populating it with data
        var width = this._plotArea.categoryAxis.box.width();
    }


    Again, this is using private APIs that are subject to change.

    May I suggest that you try using "baseUnit: 'fit'" (see automatic fitting)? This will aggregate the source data items to a predefined number of points.

    Regards,
    T. Tsonev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Dirk
    Dirk avatar
    27 posts
    Member since:
    Aug 2013

    Posted 11 Sep 2013 Link to this post

    Hi,

    your solution works fine in the dataBound event.

    In a resize (redraw for the chart) event I use $(window).width() to estimate the charts width, which is set to 100%, and this works fine too.

    Thanks for your support
    Dirk
Back to Top