igorfeiden
igorfeiden

Reputation: 177

LineChart custmization issue - JFreeChart

I'm trying to create a chart with JFreeChart. I need it to have blue lines, square markers white background and to show the values above each marker. but I need it to be very very simple. The code belhow is inside a method that recovers data from a database and put into a dataset, and generates the chart as an JPEG image.

The chart is generated, but I can't find a way to customize the chart the way I need.

My code is as shown:

// * 'graphicValues' data set is already created *

    JFreeChart graphicObject = ChartFactory.createLineChart("Classes",
            "months", //linha X
            "", //linha Y
            graphicValues, 
            PlotOrientation.VERTICAL, 
            true, 
            true,
            false);

    //Only command that seems to work
    graphicObject.setBackgroundPaint(Color.WHITE); 

     // * from here on, code works fine, I just save it as a file somewhere *

Can anyone help me to set the line to blue and show values as label over square markers?

Thank you very much!

Upvotes: 2

Views: 54

Answers (1)

GreyBeardedGeek
GreyBeardedGeek

Reputation: 30088

As the documentation for ChartFactory says, ChartFactory.createLineChart

Creates a line chart with default settings. The chart object returned by this method uses a CategoryPlot instance as the plot, with a CategoryAxis for the domain axis, a NumberAxis as the range axis, and a LineAndShapeRenderer as the renderer

So, what you get with that method is all of the default settings, and no way to customize the chart.

To customize the chart, you're probably going to have to forego the ChartFactory, and get your hands dirty subclassing some of the JFreeChart classes.

I suggest that you take a look at the source code for ChartFactory for starters—you'll see how it creates a chart, a "renderer" and a "plot" for use in rendering the chart. You'll likely have to subclass one or more of these, especially the renderer. Take a look at the LineAndShapeRenderer source code to get an idea of how a renderer works.

Upvotes: 1

Related Questions