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

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

2 Answers 167 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Dirk
Top achievements
Rank 1
Dirk asked on 02 Sep 2013, 09:53 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
T. Tsonev
Telerik team
answered on 04 Sep 2013, 03:56 PM
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!
0
Dirk
Top achievements
Rank 1
answered on 11 Sep 2013, 09:02 PM
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
Tags
Charts
Asked by
Dirk
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Dirk
Top achievements
Rank 1
Share this question
or