Question

I am using eclipse e4 and JfreeChart. The ticklabels in both xaxis and y axis are not visible.

The following is the code snippet I have used.

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);
}

I am confused why the ticklabels are not visible. I am new to Jfreechart so can anyone please tell me why is not visible?

Was it helpful?

Solution

This was a bug in the SWTGraphics2D class included in JFreeChart 1.0.14, you should not see this in later versions (1.0.17 is the current version). See also this older post.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top