ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  About setLinearScale
Posted by Daniel on Sep-20-2014 03:39
Attachments:
Hi Peter,

I noted that charts from XYChart class have the limits of scale on the Y axis are adjusted
automatically (default). If I call the function c.yAxis().setLinearScale(0, 900) the scale will
be adjusted at a certain value but there is the risk some values of the distribution to
exceed the upper limit of the scale (900 in my case). I would prefer to avoid this risk
considering a dynamic adjustment of the Y scale. As you see in the charts below when the
scale is adjusted automated the scale values step from 200 to 200 while I would prefer to
keep a step of 100 as in the first chart...How could I combine the advantages of these two
ways of adjusting the scale Y ? By default the ChartDirector functions considered to set the
maximum of the Y scale to 1000. I wonder why 1000 and not 900 as long as the maximum
spike is under 900 ? Thank you in advance.
trend auto .png
trend fix .png

  Re: About setLinearScale
Posted by Peter Kwan on Sep-22-2014 23:27
Hi Daniel,

By default, when ChartDirector automatically determines the axis scale, it will leave at
least 10% margin to avoid the data representation (line in line chart, bar in bar chart,
etc) to hit the top of the plot area. Suppose the maximum data value is 850. After adding
the margin, it would be above 900. So ChartDirector would not choose 900, but chooses
100 instead as the top scale. The margin is configurable using Axis.setAutoScale.

By default, for the y-axis, ChartDirector will ensure the labels will be at least 20 pixels
apart. So of our sample code uses the line c.yAxis().setTickDensity(30) to widen the
labeling spacing to at least 30 pixels to make the labels less crowded. If your code is
based that sample code, it may be using 30 pixels label spacing. If your plot area height
is less than 300 pixels, ChartDirector cannot choose 0, 100, 200, ..., 1000, as the label
spacing will then be less than 30 pixels. So it chooses 0, 200, 400, .... 1000 instead.

If you want ChartDirector to choose 900 as the top scale for your particular case, you
can reduce the margin, and reduce the label spacing, like:

// no margin
c.yAxis().setAutoScale(0, 0, 0.8)

//change the existing setTickDensity code to use 20 pixels
c.yAxis().setTickDensity(20)

Note that ChartDirector can still choose 0, 200, 400, ... if the data is different. For
example, if the data are from 0 to 1680, ChartDirector may determine that using 0, 100,
200, .... 1700 is too crowded even for a labeling spacing of 20 pixels, and may choose 0,
200, 400, ... 1800.

Hope this can help.

Regards
Peter Kwan

  Re: About setLinearScale
Posted by Daniel on Sep-23-2014 01:00
Hi Peter,

Thank you for this useful reply. You are right, my settings were exactly as you described
above : the PlotArea height was under 300 (275) and the TickDensity on yAxis was 30.
Now, your suggestion based on AutoScale function does cover all my needs. I understood
that first 2 arguments allow us to modify (reduce) those margin extensions (top and
bottom) but I wonder which is the role of the third ? I just see that it is called Affinity and
it is set by default to 0.8. Would you kindly explain to me what is this Affinity used for ?
Thank you.

  Re: About setLinearScale
Posted by Peter Kwan on Sep-23-2014 01:45
Hi Daniel,

The "zero affinity" parameter controls if the axis should include 0.

In most of the applications, it is natural to start the axis from 0. However, sometimes it is
not desirable to prefer 0 as the starting point. For example, stock price charts rarely starts
from 0. If the temperature varies from 65F to 87F, the temperature chart normally would
not look natural if it starts from 0.

ChartDirector will choose to start the axis from 0 if the data variation is large. For example,
if your data are from 12 to 86, ChartDirector may choose 0 to 90 instead of 10 to 90. If the
data variation is small, it may not start from 0. For example, if the data is 88.12 to 88.86,
ChartDirector may choose 88.1 to 88.8 as the axis scale. By default, ChartDirector
considers the data variation to be large if min_data_value < max_data_value * 0.8. The 0.8
is the zero affinity parameter and is configurable.

It follows if zero affinity is 1, ChatDirector will always include 0 in the axis scale. If zero
affinity is 0, ChartDirector will not give preference to 0.

Hope this can help.

Regards
Peter Kwan

  Re: About setLinearScale
Posted by Daniel on Sep-23-2014 02:41
Hi Peter,
Your explanation is complete. From now on I will always use the AutoScale function. It is
very useful in many situations. Thank you for all these details.
Kind regards,
Daniel