Stacked Area Chart, fixed y axis label width

2019-06-28 03:10发布

问题:

I am creating a JFreeChart stacked area chart.

I want my y axis label's width to be fixed, and I don't want to shift the chart as the width increases. See the image explaining the problem.

error http://s8.postimage.org/yyzvhpqet/fixeddimension_bug.jpg

I am facing similar problem as posted on the JFreeChart forum. As per the forum it is fixed, but it is not yet released. Does any body knows its fix. We can't wait for next release, does any body knows a hack which we can apply?

Hoping for some solution.

回答1:

A possible solution is to override the findMaximumTickLabelWidth() for rangeaxis of the chart. The maximum width can be hardcoded to a specific value or can be taken as max value of maximum width and calculated maximum width.



回答2:

As an alternative, consider a CombinedDomainCategoryPlot, illustrated here. A CombinedDomainXYPlot is shown here.



回答3:

There is another method to get the plots aligned. You can reserve some space on the left, right top or bottom of your plot to display the Range axes.

      AxisSpace space = new AxisSpace();
      space.setRight(50); //reserved space on the left side of the plot
      space.setLeft(50);
      plot.setFixedRangeAxisSpace(space);
      plot2.setFixedRangeAxisSpace(space);

I know, this is not the best solution for multiple plots. But you can solve the problem in a quick way.