Jfreechart中缺少TickLabels

时间:2014-03-10 14:20:13

标签: eclipse jfreechart e4

我正在使用eclipse e4和JfreeChart。 x轴和y轴上的刻度标签都不可见。

以下是我使用过的代码段。

public class showGraph {
String title = null;
final TimeSeriesCollection dataset = new TimeSeriesCollection();
Map<String,Map<String,Map<String,Long>>> StatisticsValues = null;
String statistics = "MIN";
@Inject
public showGraph() {
    //TODO Your code here
}

@PostConstruct
public void postConstruct(Composite parent) {

    final JFreeChart chart = createChart(dataset,title);
    new ChartComposite(parent,SWT.NONE,chart,true); 
}

private JFreeChart createChart(TimeSeriesCollection dataset, String string) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, "TimeStamp", "ms", dataset, true, true, false);
    chart.setBackgroundPaint(Color.WHITE);
    final XYPlot plot = (XYPlot)chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.BLACK);
    plot.setRangeGridlinePaint(Color.BLACK);
    Shape shape = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesShape(0, shape);
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesFillPaint(0, Color.YELLOW);
    renderer.setSeriesOutlinePaint(0, Color.GRAY);
    renderer.setUseFillPaint(true);
    NumberAxis yaxis = (NumberAxis) plot.getRangeAxis();
    yaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yaxis.setAutoRangeIncludesZero(false);
    yaxis.setVerticalTickLabels(true);
    plot.setRangeAxis(yaxis);
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
    DateAxis.createStandardDateTickUnits();  
    axis.setTickMarksVisible(true);  
    axis.setTickLabelsVisible(true);
    return chart;

}


/* setInputForChart get the value from a handler */

public void setInputForChart(HashMap<Timestamp,Long> requestTimeToTimeDiff) {
    final TimeSeries s1 = new TimeSeries("XYZ", Second.class);
    Timestamp TimestampValueWithInterval =null;
    TreeMap<Timestamp,Long> requestTimeToTimeDiffSorted = new TreeMap<Timestamp,Long>(requestTimeToTimeDiff);
    HashMap<Timestamp,Long> MinutesToMin = new HashMap<Timestamp,Long>();
    Long MinValue = Long.MAX_VALUE;
    boolean bool = true;
    Timestamp tsWithMinValue = null;
    for (Entry<Timestamp,Long> reqTodiffMap : requestTimeToTimeDiffSorted.entrySet()) {
        /* some operations I do to insert in MinutesToMin */
    } 
    for(Entry<Timestamp,Long> seriesData : MinutesToMin.entrySet()){
    s1.add(new Second(seriesData.getKey()), seriesData.getValue());
    }
     dataset.addSeries(s1);
     dataset.setDomainIsPointsInTime(true);
}

我很困惑为什么滴答标签不可见。我是Jfreechart的新手,所以任何人都可以告诉我为什么不可见?

1 个答案:

答案 0 :(得分:3)

这是JFreeChart 1.0.14中包含的SWTGraphics2D类中的一个错误,您不应该在以后的版本中看到这个错误(1.0.17是当前版本)。另请参阅this older post