|
Calculating Width of y-axis including labels |
Posted by Peter Schilling on Nov-03-2015 15:52 |
|
Hello there,
I have build a absolute dynamic chart to display various production data (mixture of binary
and analog data).
But I have problems to arrange the y-axis according to the length of the labels and ticks.
Is there a way to calculate the exact width of an y-axis so I can arrange them without
writing one label over the next y-axis.
E.G.: If I make a fix distance of 50 pixels between 2 y-axis and the value of the are very
long like 100000 nothing fits anymore..
Hope you got a hint for me!
Greetings,
Peter
|
Re: Calculating Width of y-axis including labels |
Posted by Peter Kwan on Nov-04-2015 02:29 |
|
Hi Peter,
First, set up the chart with all the axes as usual, and entering all the data into the chart
object. Then you can use BaseChart.layout to ask ChartDirector to automatically determine
the axis scale. After that, you can use Axis.getThickness to get the "thickness" of the axis,
and then use Axis.setOffset to re-position the axis.
For example, in the "Multiple Axes" sample code, to put the leftAxis immediately to the left
of the primary y-axis without overlapping with its labels, the code is like (in C#/Java):
.... create chart as usual .....
//auto-scale axes
c.layout();
//the left axis is immediately to the left of the primary y-axis
leftAxis.setOffset(-c.yAxis().getThickness(), 0);
Hope this can help.
Regards
Peter Kwan |
Re: Calculating Width of y-axis including labels |
Posted by Peter Schilling on Nov-04-2015 16:30 |
|
Hello Peter,
thank you for your reply. It works but was little more work to do to calculate the left-
position of the plotarea.
Now I do a 'calculating' run at the very first drawing to get the width of all y-axis.
I need this overall width of all y-axis for the left parameter in setPlotArea(....)
// Collecting all y-axis in List allYaxis and at the end of the drawChart function:
c.layout();
if (m_bFirstCalc )
{
m_bFirstCalc = false;
m_axisWidth = 0;
for (int i = 0; i < allYaxis.Count; i++)
{
Axis a = allYaxis[i];
m_axisWidth += a.getThickness();
}
}
else
{
int offset = c.yAxis().getThickness();
for (int i = 0; i < allYaxis.Count; i++)
{
Axis lAxis = allYaxis[i];
lAxis.setOffset(-offset, 0);
offset += lAxis.getThickness();
}
}
c.packPlotArea(m_plotArea.Left, m_plotArea.Top, m_plotArea.Width,
m_plotArea.Height);
trackLine(c, chart.IsMouseOnPlotArea ? chart.PlotAreaMouseX :
c.getPlotArea().getRightX());
}
What do you think? Not very elegant, isn't it??
Nevertheless my chart is looking fine now
Thank you very much!
Greetings,
Peter |
|