|
packPlotArea and multi charts |
Posted by sroeber on Feb-28-2025 19:40 |
|
Hi,
I have a problem with multiple charts and the packPlotArea() function. If I call packPlotArea(), it may cause the left side of the plot area to differ between the charts. How can I ensure that all charts start at the same x-position? Without using packPlotArea(), I would need to set the x offset in setPlotArea() manually depending on the values/width of the y-axis.
Best regards
Steffen |
Re: packPlotArea and multi charts |
Posted by Peter Kwan on Mar-01-2025 00:00 |
|
Hi Soreber,
packPlotArea always pack the plot area, including the axis labels and axis title, to within a given bounding box. As the label length can be different between charts, if you use the same bounding box, the left x-axis of the charts may not align.
After some thoughts, I think of the following method, which I have tried myself and it works in my case.
As I am not sure which programming language you are using, I randomly choose to use C# in the code example below:
Suppose you have 3 XYCharts, which are to be added to the MultiChart:
XYChart c[] = { c0, c1, c2 };
//Pack the plot area, and determine the chart with the smallest plot area width. This
//is the chart with the longest x-axis labels
int minPlotAreaWidth = 9999999999;
for (int i = 0; i < c.Length; ++i) {
c[i].packPlotArea(leftX, topY, rightX, bottomY);
minPlotAreaWidth = Math.Min(minWidth, c[i].getPlotArea().getWidth());
}
//For charts that have longer plot area width, they should be packed again with a
//smaller bounding box to make it the same width as the other charts.
for (int i = 0; i < c.Length; ++i) {
int extraWidth = c[i].getPlotArea().getWidth() - minPlotAreaWidth;
if (extraWidth > 0)
c[i].packPlotArea(leftX+extraWidth, topY, rightX, bottomY);
}
If you need to translate the code to another programming language, please let me know.
Best Regards
Peter Kwan |
Re: packPlotArea and multi charts |
Posted by sroeber on Mar-03-2025 15:46 |
|
Hi Peter,
thanks that works for me as well. |
|