Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#723 alternating lines for XYSeries

closed
David Gilbert
General (896)
5
2007-03-05
2007-02-23
Don Brutzman
No

Lines connecting points in an XYSeries are zigzagging up and down instead of going from one point to the next.

Code excerpts follow, nothing outlandish or unusual is intended. The same results occur using jfreechart 1.0.3 and 1.0.4.

=============================

/** JFreeChart datasetXy collecting X and Y series data */
private XYSeriesCollection datasetXy = new XYSeriesCollection ();

/** jfreeChart XYSeries for x,y values in a geographic plot */
private XYSeries seriesXY = new XYSeries ("Geographic plot");

//loop:
seriesXY.add (x, y);

private JFreeChart createChart (XYDataset dataset, String title)
{
if (dataset instanceof TimeSeriesCollection)
{
chart = ChartFactory.createTimeSeriesChart (
title, // title
"time", // x-axis label
"meters", // y-axis label
dataset, // data
true, // create legend?
true, // generate tooltips?
false // generate URLs?
);
}
else if (dataset instanceof XYSeriesCollection)
{
chart = ChartFactory.createXYLineChart (
title, // title
"meters", // x-axis label
"meters", // y-axis label
dataset, // data
PlotOrientation.VERTICAL,
true, // create legend?
true, // generate tooltips?
false // generate URLs?
);
}
// customize chart appearance
chart.setBackgroundPaint (Color.white);

XYPlot plot = (XYPlot) chart.getPlot ();
plot.setBackgroundPaint (Color.white);
plot.setDomainGridlinePaint (Color.lightGray);
plot.setRangeGridlinePaint (Color.lightGray);
plot.setAxisOffset (new RectangleInsets (5.0, 5.0, 5.0, 5.0));
plot.setDomainCrosshairVisible (true);
plot.setRangeCrosshairVisible (true);

XYItemRenderer r = plot.getRenderer ();
if (r instanceof XYLineAndShapeRenderer)
{
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
renderer.setBaseShapesVisible (true);
renderer.setBaseShapesFilled (true);
renderer.setDrawSeriesLineAsPath (true); // TODO debug zigzag linedraw on X Y geo plot
}

Axis axis = (Axis) plot.getDomainAxis ();
if (axis instanceof DateAxis)
{
if (isPlotRelativeTimeOnDomainAxis ()) // TODO: also include hours if total interval > 60 minutes
{
DateAxis timeAxis = (DateAxis) plot.getDomainAxis ();
timeAxis.setDateFormatOverride (new SimpleDateFormat ("mm:ss"));
}
else
{
DateAxis timeAxis = (DateAxis) plot.getDomainAxis ();
timeAxis.setDateFormatOverride (new SimpleDateFormat ("HH:mm:ss"));
}
}
// getDomainAxis() might also yield CategoryAxis, NumberAxis, PeriodAxis

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis ();
rangeAxis.setAutoRange (true);

return chart;
}

Discussion

  • Don Brutzman
    Don Brutzman
    2007-02-23

    XYPlotAlternationProblem.png

     
  • Don Brutzman
    Don Brutzman
    2007-02-23

    Logged In: YES
    user_id=603256
    Originator: YES

    File Added: XYPlotAlternationProblemZoom.png

     
  • Sergei Ivanov
    Sergei Ivanov
    2007-02-27

    Logged In: YES
    user_id=1606022
    Originator: NO

    I think it is not a bug.
    You are using the XYSeries(Comparable) constructor, which defaults 'autoSort' property to 'true'. You need to use the alternative constructor:

    private XYSeries seriesXY = new XYSeries ("Geographic plot", false);

    The 'autoSort' property is read-only and can only be specified at the time of initialisation.

    Hope that helps.

     
  • David Gilbert
    David Gilbert
    2007-03-05

    • assigned_to: nobody --> mungady
    • status: open --> closed
     
  • David Gilbert
    David Gilbert
    2007-03-05

    Logged In: YES
    user_id=112975
    Originator: NO

    I tend to agree with Sergei, although it is hard to tell from the information you've provided. I'll close this, but please feel free to reopen it if you can provide a runnable test case that we can debug.

    Regards,

    Dave Gilbert
    JFreeChart Project Leader

     
  • Don Brutzman
    Don Brutzman
    2007-04-01

    Logged In: YES
    user_id=603256
    Originator: YES

    this correction worked well - thank you