Menu

ChartPostProcessor

2005-01-14
2013-01-13
  • javacodeforger

    javacodeforger - 2005-01-14

    Hi,
    I'm trying to create a ChartProstProcessor

    When I try to display the chart it throw the error
    de.laures.ceworlf.PostProcessingException:java.lang.ClassCastException

    just when its doing this line
    DateAxis dateAxis = (DateAxis)xyPlot.getDomainAxis();

    ------this is my class for post processing------

    public class XYChartPostProcessor implements ChartPostProcessor
    {
      public void processChart(Object object, Map params)
      {
        JFreeChart chart = (JFreeChart)object;
        System.out.println("one");
        XYPlot xyPlot = chart.getXYPlot();
        System.out.println("two");
        DateAxis dateAxis = (DateAxis)xyPlot.getDomainAxis();
        System.out.println("three");
        dateAxis.setDateFormatOverride(new SimpleDateFormat("dd.MM.yyyy"));
        System.out.println("four");
      }
    }

    ----------------------------------------
    my data producer is for the xy type chart
    and the produceData method is as listed below

      public Object produceDataset(Map map) throws DatasetProduceException
      {
        TimeSeries timeseries = new TimeSeries(producerId, org.jfree.data.time.Day.class);

        List data = this.dataList;

        for(int i=0; i<data.size();i++)
        {
          StockQuoteHistory quote =  (StockQuoteHistory)data.get(i);
          Date date = quote.getQuoteTime();
          Day dayT = new Day(date);
          timeseries.add(dayT, quote.getClosePrice());
        }

        TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
        timeseriescollection.addSeries(timeseries);

        return (XYDataset)timeseriescollection;
      }

    ----------------------------

    so i'm returning the timeseriescollection cast as XYDataset.

    When I execute my application without the ChartPostProcessor tag it works fine. Just that it displays the X axis as milliseconds. I'm trying to get it to display as date.

     
    • Zoltan Luspai

      Zoltan Luspai - 2005-01-17

      Hi,

      Since axis is not a DateAxis instance (but a NumberAxis class as see in ChartFactory.createXYLineChart method).

      You're free to create and use your own DateAxis:

      DateAxis dateAxis = new DateAxis();
      xyplot.setDateAxis(dateAxis);
      ...

      Well you may need to configure this dateAxis like the date format.

       

Log in to post a comment.