English 中文(简体)
Jfreechart: 在特定单位之后显示带有值的 X 轴
原标题:JFreechart: Displaying X axis with values after specific units
  • 时间:2012-05-25 11:53:43
  •  标签:
  • jfreechart

我正在使用 jfreet 图表显示线条图。 现在, 在 X 轴上, 它显示图表上每对( x, y) 的值 。 因此 X 轴有大量的值被重叠 。 我想在每5 个单位或类似单位之后显示很少的值 。 使用 Jfreechart 如何可能 。

问题回答

在绘制图表图图的 numberAxis 之前,要刷新其刻记。结果为 List , 其中包括一个 NumberTick 对象, 用于轴的每个刻记 。

通过覆盖函数 numberAxis.refreshTicks , 您可以控制标记的显示方式和时间 。

例如,在下面的代码中,我得到所有的勾记,然后通过它们循环查找 TickType.MAJOR 。如果一个大勾记的值不能用 5 来调和,它会被一个小勾记替换 。

因此,只有可除以5的数值才用文字标签显示。

XYPlot plot = (XYPlot) chart.getPlot();

NumberAxis myAxis = new NumberAxis(plot.getDomainAxis().getLabel()) {
  @Override
  public List refreshTicks(Graphics2D g2, AxisState state,
                           Rectangle2D dataArea, RectangleEdge edge) {

    List allTicks = super.refreshTicks(g2, state, dataArea, edge);
    List myTicks = new ArrayList();

    for (Object tick : allTicks) {
      NumberTick numberTick = (NumberTick) tick;

      if (TickType.MAJOR.equals(numberTick.getTickType()) &&
                    (numberTick.getValue() % 5 != 0)) {
        myTicks.add(new NumberTick(TickType.MINOR, numberTick.getValue(), "",
                    numberTick.getTextAnchor(), numberTick.getRotationAnchor(),
                    numberTick.getAngle()));
        continue;
      }
      myTicks.add(tick);
    }
    return myTicks;
  }
};

plot.setDomainAxis(myAxis);




相关问题
Can t find bundle for base name

I m using a library that has a dependency on jfreechart (v 1.0.9). When I try to run the .jar, I get: java.util.MissingResourceException: Can t find bundle for base name org.jfree.chart....

How to prevent duplication of bar chart in iReport

I ve tried to use chart in iReport for the first time. I ve used a bar chart and anytime I preview the chart I see plenty of them, iIthink about 6. I only need a single one is there anything that I ...

Width of the bar in Jfreechart

Is there a way to adjust the width of the bars in a Barchart? I create my chart with the following code. final JFreeChart chart = ChartFactory.createBarChart("Report", // chart title ...

How to handle mouse dragging event in JFreeChart

I want to know whether it is possible to listen to the mouse event of dragging in JFreeCharts. By default it is assign to zooming. I remove this zooming functionality with, chartPanel....

JFreeChart in scrollpane

I m having a big graph created with jfreechart. This chart is too big for the screen, so I would like to put it in a scrollpane. However, when using the scrollbar, the complete graph is redrawn ...

JFreeChart connecting points in stacked bar charts

I created a stacked bar chart using JFreeChart (similar to this one). Now I would like to connect the points of the corresponding series for all rows. Is this possible using JFreeChart?

热门标签