1

enter image description here

I need to start the chart at 00:00 and end it at 11:59 (24 hour period) I am new to JFreeChart and I am trying to read the Api but could not figure out a way to make this work.

my dataset runs from 00:00am to 11:59pm, what should I set lowerbound value to

I tried setLowerbound(startTime);

This simply keep loading and no graph is generated.

public JFreeChart createLoudnessChart(TimeZone tz,
                                      long startTime, 
                                      long endTime, 
                                      List<ProgramMetricsData> metrics,
                                      long flowId,
                                      int locationNdx,
                                      String tuple,
                                      int programNum,
                                      String programName,
                                      int pid,
                                      String audioChn,
                                      DVAResourceBundle resourceBundle)
{
    JFreeChart jfreechart = ChartFactory.createXYLineChart("", "", "", createDataset(startTime, endTime, metrics, resourceBundle), PlotOrientation.VERTICAL, true, true, false);

    XYPlot xyplot = (XYPlot)jfreechart.getPlot();

    xyplot.setDomainPannable(true);
    xyplot.setRangePannable(true);

    DateAxis dt = new DateAxis( resourceBundle.getI18NString("common.hour") );
    dt.setTimeZone(tz);
    dt.setLabelFont(new Font("simsun", Font.BOLD,12));

    dt.setVerticalTickLabels(true);


    xyplot.setDomainAxis(dt); //Need to pass TimeZone ....

    xyplot.setBackgroundPaint(new Color(249,249,249));
    xyplot.setDomainGridlinePaint(Color.GRAY);
    xyplot.setRangeGridlinePaint(Color.GRAY);

    DateAxis axis = (DateAxis) xyplot.getDomainAxis();
    axis.setTimeZone(tz);
    axis.setDateFormatOverride(DateFormat.getDateInstance(DateFormat.SHORT));

    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    sdf.setTimeZone(tz);
    axis.setDateFormatOverride(sdf);

    DateTickUnit tickUnit = new DateTickUnit(DateTickUnitType.MINUTE, 30);        
    axis.setTickUnit(tickUnit);

    NumberAxis numberaxis = (NumberAxis)xyplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(true);        
    numberaxis.setRangeWithMargins(-70.0,0.0);        

    XYErrorRenderer xyerrorrenderer = new XYErrorRenderer();
    xyerrorrenderer.setBaseLinesVisible(true);
    xyerrorrenderer.setBaseShapesVisible(false);       
    xyerrorrenderer.setBaseFillPaint(java.awt.Color.white);
    xyerrorrenderer.setSeriesPaint(0, Color.RED);
    xyerrorrenderer.setSeriesPaint(1, Color.BLUE);     

    IQXYToolTipGenerator toolTipGen = new IQXYToolTipGenerator(resourceBundle);
    xyerrorrenderer.setBaseToolTipGenerator(toolTipGen);

    IQXYURLGenerator urlGenerator = new IQXYURLGenerator(flowId, tuple, programNum, programName, pid, audioChn, locationNdx);
    xyerrorrenderer.setURLGenerator(urlGenerator);

    xyplot.setRenderer(xyerrorrenderer);

    jfreechart.setBackgroundPaint (new Color(239, 243, 250));
    jfreechart.setBorderVisible(false);
    jfreechart.getLegend().setItemFont(new Font("simsun", Font.BOLD,12));

    return jfreechart;
}

Can any one help me with an example

  • Possible duplicate of [To change the X-axis starting value of graph in Jfreechart](http://stackoverflow.com/questions/21072958/to-change-the-x-axis-starting-value-of-graph-in-jfreechart) – Egg Mar 22 '16 at 15:07
  • I tried setting lowerbond to 0, it did not help So I asked the question. [code] DateAxis axis = (DateAxis) xyplot.getDomainAxis(); axis.setTimeZone(tz);[/code] – Rushabh Badani Mar 22 '16 at 15:36
  • Update your question with your code so others can see what you are doing :) – Egg Mar 22 '16 at 16:13
  • Hey I got it working, Thanks. – Rushabh Badani Mar 22 '16 at 18:35

0 Answers0