Line chart with different thickness

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
t30n3
Posts: 2
Joined: Tue Sep 15, 2009 4:26 pm
antibot: No, of course not.

Line chart with different thickness

Post by t30n3 » Tue Sep 15, 2009 4:38 pm

Hi everybody,
I'm wondering if it's possible to create a line chart with a specific line thicker than the others.

I'm using the last version of JFreeChart, and here's an example of how the chart is:

Image

My goal is to get thicker lines corresponding to (*) data.

Thanks

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Re: Line chart with different thickness

Post by skunk » Tue Sep 15, 2009 5:01 pm

Call this method in your renderer

Code: Select all

public void setSeriesStroke(int series, java.awt.Stroke stroke)

artipton
Posts: 16
Joined: Thu Jul 03, 2008 6:59 pm

Re: Line chart with different thickness

Post by artipton » Tue Sep 15, 2009 7:48 pm

Afternoon,

Here is a code snippet...

chartPane.getChart().getXYPlot().getRenderer().setSeriesStroke(i, new BasicStroke(2.0f));

Andy

t30n3
Posts: 2
Joined: Tue Sep 15, 2009 4:26 pm
antibot: No, of course not.

Re: Line chart with different thickness

Post by t30n3 » Wed Sep 16, 2009 11:25 am

Thanks for your reply.

The method you suggest me accept a "series" parameter; my chart is built dynamically and I don't know how many lines it will draw, so how do I cycle through it??
I assume it could be something like that, but I don't know which method I can call...

Code: Select all

for (int i=0; i < number_of_lines; i++)
{
    check label value to find (*)
    renderer.setSeriesStroke(i, new BasicStroke(3.5f));
}
Can you suggest me the method to call to get the number of lines and how to get the label associated??

Thanks in advance

EDIT: I found a way to cycle, now I only need the method to check the label value.
Thanks again

artipton
Posts: 16
Joined: Thu Jul 03, 2008 6:59 pm

Re: Line chart with different thickness

Post by artipton » Wed Sep 16, 2009 1:05 pm

Morning,

I also create and modify my chart on the fly... I pass a vector of objects in and build the set of TimeSeries for that vector like this...

private void setTimeSeries()
{
for (int i = 0; i < legends.size(); i++)
{
TagLegend legend = (TagLegend) legends.elementAt(i);
String tagname = legend.getTagName();
addTimeSerie( tagname );
chartPane.getChart().getXYPlot().getRenderer().setSeriesPaint(i, legend.getColor());
chartPane.getChart().getXYPlot().getRenderer().setSeriesStroke(i, new BasicStroke(2.0f));
}
}

private void addTimeSerie(String tagName)
{
TimeSeries series = new TimeSeries( tagName );
series.add( new Millisecond(), 0 );
series.setMaximumItemCount( MAX_SAMPLE_COUNT );
series.removeAgedItems( true );
series.setMaximumItemAge( HISTORY_COUNT );
timeSeries.add( series );
dataSet.addSeries( series );
}

Hope this helps...

Locked