0

Currently I am using JfreeChart to create dynamic charts. Now am facing problem with XY chart. I want show some fixed string label names on Y axis and same time X axis have to fix with dynamic Date time values. How would I customize the X axis and Y axis. Here I have tried using TimeSeriesChart. Sample code here

    TimeSeries s1 = new TimeSeries("Encounter Summary");
    s1.add(new Year(2001), 181.8);
    s1.add(new Year(2002), 167.3);
    TimeSeriesCollection timeset = new TimeSeriesCollection();
    timeset.addSeries(s1);
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Encounter Summary","Words",  "Activation", timeset, true,true,false);
    XYPlot plot = (XYPlot) chart.getPlot();
    String[] months =  new String[2];
    months[0] = "Jan";
    months[1] = "Feb";
    SymbolAxis rangeAxis = new SymbolAxis("Activation", months);
    rangeAxis.setTickUnit(new NumberTickUnit(1));
    rangeAxis.setRange(0,months.length);
    plot.setRangeAxis(rangeAxis);

When I tried above code i am able to see chart but not showing data line points in chart, When I commented SymbolAxis part its showing data points. I am suspecting SymbolAxis is not working with TimeSeries. When i used createXYLineChart instead of createTimeSeriesChart then succesfully showing data axis points in chart. Please help me to solve this problem.

Actually my requirement is Y axis fixed with month names Jan,Feb,Mar,Apr..Dec and same time X axis have to show dynamic data time values. Please refer below image.

enter image description here

ChrisB
  • 2,497
  • 2
  • 24
  • 43
Praveen
  • 11
  • 2
  • I'm pretty sure they work together. Why not use a `DateAxis` like I said [here](http://stackoverflow.com/a/40281667/261156)? – Catalina Island Nov 02 '16 at 09:27
  • Hi Catalina Island, I am very new to creating charts. Present I am using TimeSeries to set the data. Ex: TimeSeries s1 = new TimeSeries("Encounter Summary"); s1.add(new Year(2001), 0); s1.add(new Year(2002), 1); setting X axis with Date and Y axis double value. When I used DateAxis to set String label names on Y axis DateAxis axis = (DateAxis) plot.getRangeAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM")); Getting ClassCastException exception : org.jfree.chart.axis.NumberAxis cannot be cast to org.jfree.chart.axis.DateAxis. – Praveen Nov 03 '16 at 02:26
  • If this is not a duplicate, and for easier reading, please [edit](http://stackoverflow.com/posts/40372755/edit) your question to include a [mcve] that shows your current approach and a stack trace that shows any error. – trashgod Nov 03 '16 at 06:05

0 Answers0