chrisrhyno2003
chrisrhyno2003

Reputation: 4177

Jfreechart - can we set a shape for a datapoint in StackedAreaChart?

I am using Jfreechart to make a stacked area chart. I am using the class StackedXYAreaChart.

I wanted to know if we could draw shapes at data points for the StackedAreaChart, (it a line chart we can denote each data point by setting the SetSeriesShapes()).

The method setSeriesShape() doesn't seem to work. Anyone have any idea ?

Here's what I have tried till now (Please do not comment that I have an empty dataset. I am plotting a dynamic graph and the series would be filled later ):

 incomingData = new TimeTableXYDataset();
final JFreeChart incomingDataChart = ChartFactory.createStackedXYAreaChart(
            "Chart", "Time", "Payload (In Bytes)", incomingData, PlotOrientation.VERTICAL, true, true, false);
    final StackedXYAreaRenderer renderChart = new StackedXYAreaRenderer();
    renderChart.setSeriesPaint(0, Color.decode("#339900"));
    renderChart.setSeriesPaint(1, Color.decode("#CC9933"));
    renderChart.setSeriesPaint(2, Color.decode("#33CCFF"));
    renderChart.setSeriesPaint(3, Color.decode("#FF6600"));
    renderChart.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 10, 10));
    renderChart.setSeriesShape(1, new Ellipse2D.Double(-3, -3, 10, 10));
    renderChart.setSeriesShape(2, new Ellipse2D.Double(-3, -3, 10, 10));
    renderChart.setSeriesShape(3, new Ellipse2D.Double(-3, -3, 10, 10));
    incomingDatachart.getPlot().setRenderer(renderChart);

Upvotes: 1

Views: 310

Answers (2)

chrisrhyno2003
chrisrhyno2003

Reputation: 4177

Figured the solution out : Use the Statement

StackedXYAreaRenderer renderChart = new StackedXYAreaRenderer(StackedXYAreaRenderer.AREA_AND_SHAPES);

Then use,

renderChart.setSeriesShape(index, Shape);

Upvotes: 1

Phill Treddenick
Phill Treddenick

Reputation: 1420

You need to set the type of the StackedXYAreaRenderer to be "shapes and lines". That renderer doesn't show the shapes by default.

StackedXYAreaRenderer renderer = new StackedXYAreaRenderer(StackedXYAreaRenderer.SHAPES_AND_LINES);

Upvotes: 2

Related Questions