A smoother drawing of XYSplineRenderer?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
maverick39
Posts: 6
Joined: Tue Jul 20, 2010 9:03 am
antibot: No, of course not.

A smoother drawing of XYSplineRenderer?

Post by maverick39 » Wed Dec 22, 2010 12:53 pm

Hi there,

I have a chart which I plotted using the XYSplineRenderer (since I have XYSeries in an XYSeriesCollection dataset). This looks like the following:

[img]
http://dl.dropbox.com/u/512384/loadprof ... echart.PNG
[/img]

(There are 168 hours in a week)
As you see, this looks quite shabby. How can I get the splines to be drawn without explicitly displaying the datapoints, so that it looks more like this:

[img]
http://dl.dropbox.com/u/512384/loadprof ... okLike.PNG
[/img]

(By the way: How to get the x-Axis values to be more like in this chart is another topic I need to deal with ...)


And this is my code for displaying the chart:

Code: Select all

public class LoadProfileChart extends ApplicationFrame  {

	//the dataset collection which holds all datasets (one dataset = 1 spline) to be drawn in the chart
	XYSeriesCollection datasetCollection = new XYSeriesCollection(); 
	
	//the profile summing up the h0 load and the EV load and subtracting the PV feed in
	XYSeries seriesSumLoadProfile = new XYSeries("Sum Load");

	//chart labeling	
	String chartTitle;
	String xAxisLabel = "hour";
	String yAxisLabel = "kW";
	
	public LoadProfileChart(String title) {
		super(title);
		this.chartTitle = title;
	}
	
	public JFreeChart createChart() {
		JFreeChart chart = ChartFactory.createXYLineChart(
				chartTitle,		  			
				xAxisLabel,					
				yAxisLabel,				 	
				datasetCollection, 					
				PlotOrientation.VERTICAL, 			
				true, 						//include legend
				false, 						//tooltips
				false						//urls (only needed for creation of html image maps)		
		);
		ChartPanel chartPanel = new ChartPanel(chart);
		chartPanel.setPreferredSize(new java.awt.Dimension(1250, 600));
		setContentPane(chartPanel);
		chart.getXYPlot().setRenderer(setSplineColors(datasetCollection));
		
		return chart;
	}
	
	//set the colors for each drawn dataset (or spline)
	private XYSplineRenderer setSplineColors(XYSeriesCollection datasetCollection) {
		XYSplineRenderer xySplineRender = new XYSplineRenderer();
		
		for (int i=0; i < datasetCollection.getSeriesCount(); i++) {
			String seriesName = (String) datasetCollection.getSeriesKey(i);
			
			if (Constants.contains(Constants.TITLES_H0_Profile, seriesName)) {
				xySplineRender.setSeriesPaint(i, Color.BLUE);
			} else if (Constants.contains(Constants.TITLES_PV_Profile, seriesName)) {
				xySplineRender.setSeriesPaint(i, Color.YELLOW);
			} else if (Constants.contains(Constants.TITLES_CHARGE_STRATEGY, seriesName)) {
				xySplineRender.setSeriesPaint(i, Color.GREEN);
			} else if (Constants.TITLE_SUM_LOAD.equals(seriesName)) {
				xySplineRender.setSeriesPaint(i, Color.RED);
			} else {
				xySplineRender.setSeriesPaint(i, Color.BLACK);
			}
		}
		
		return xySplineRender;
	}
	
	public void show(SmartChargingManager scm) {
		this.createChart();
		this.pack();
		RefineryUtilities.centerFrameOnScreen(this);
		this.setVisible(true);
	}
}
Thanks for any help!
Marc

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

Re: A smoother drawing of XYSplineRenderer?

Post by skunk » Wed Dec 22, 2010 2:51 pm

Code: Select all

public void setBaseShapesVisible(boolean flag)

maverick39
Posts: 6
Joined: Tue Jul 20, 2010 9:03 am
antibot: No, of course not.

Re: A smoother drawing of XYSplineRenderer?

Post by maverick39 » Wed Dec 22, 2010 3:35 pm

Thanks!! :)

Locked