Solved

JFreeChart: CombinedDomainXYPlot

Posted on 2011-09-27
12
618 Views
Last Modified: 2012-05-12
I have a CombinedDomainXYPlot with 3 subplots (XYPlot).

I am trying to make the base shape visible and fill it with this code, but it does not seem to work. If possible, please let me know what I am missing. Thanks!
XYItemRenderer r = plot.getRenderer();
        if (renderer instanceof XYLineAndShapeRenderer) {
        	XYLineAndShapeRenderer lineAndShapeRenderer = (XYLineAndShapeRenderer) r;
        	lineAndShapeRenderer.setBaseShapesVisible(true);
        	lineAndShapeRenderer.setBaseShapesFilled(true);
        }

Open in new window

0
Comment
Question by:dshrenik
  • 6
  • 6
12 Comments
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Strange that it does not work.
Maybe you could try to use ...ShapesVisible(..) and ...ShapesFilled(...)  methods specific to series ?
0
 

Author Comment

by:dshrenik
Comment Utility
Can you tell me how I can do that?
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
Comment Utility
0
 

Author Comment

by:dshrenik
Comment Utility
Even this code does not seem to work:
final XYItemRenderer renderer = plot.getRenderer();
		
		if (renderer instanceof StandardXYItemRenderer) {
			final StandardXYItemRenderer itemRenderer = (StandardXYItemRenderer) renderer;
			itemRenderer.setSeriesStroke(0, new BasicStroke(2.0f));
			itemRenderer.setSeriesStroke(1, new BasicStroke(2.0f));
		}
		
        if (renderer instanceof XYLineAndShapeRenderer) {
        	XYLineAndShapeRenderer lineAndShapeRenderer = (XYLineAndShapeRenderer) renderer;
        	//lineAndShapeRenderer.setBaseShapesVisible(true);
        	//lineAndShapeRenderer.setBaseShapesFilled(true);
        	lineAndShapeRenderer.setSeriesShapesVisible(0, true);
        	lineAndShapeRenderer.setSeriesShapesFilled(0, true);
        }

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Maybe you can post your code - I could then try to play with it
0
 

Author Comment

by:dshrenik
Comment Utility

CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(new DateAxis(""));
		mainPlot.setGap(10.0);
		
		final TimeSeriesCollection dataset1 = new TimeSeriesCollection();
		final TimeSeriesCollection dataset2 = new TimeSeriesCollection();
		final TimeSeriesCollection dataset3 = new TimeSeriesCollection();
		final TimeSeries series1 = new TimeSeries("A");
		final TimeSeries series2 = new TimeSeries("B");
		final TimeSeries series3 = new TimeSeries("C");
		final TimeSeries series4 = new TimeSeries("D");
		
		Minute xValue;
		double yValue1, yValue2, yValue3, yValue4;
///		
// I add values to all 4 series here
///
		}

		dataset1.addSeries(series1);
		dataset2.addSeries(series2);
		dataset2.addSeries(series3);
		dataset3.addSeries(series4);

		XYItemRenderer renderer1 = new StandardXYItemRenderer();
		NumberAxis rangeAxis1 = new NumberAxis("");
		XYPlot subplot1 = new XYPlot(dataset1, null, rangeAxis1, renderer1);
		subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
		
		XYItemRenderer renderer2 = new StandardXYItemRenderer();
		NumberAxis rangeAxis2 = new NumberAxis("");
		rangeAxis2.setAutoRangeIncludesZero(false);
		XYPlot subplot2 = new XYPlot(dataset2, null, rangeAxis2, renderer2);
		subplot2.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
		
		XYItemRenderer renderer3 = new StandardXYItemRenderer();
		NumberAxis rangeAxis3 = new NumberAxis("");
		rangeAxis3.setAutoRangeIncludesZero(false);
		XYPlot subplot3 = new XYPlot(dataset3, null, rangeAxis3, renderer3);
		subplot3.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
		
		mainPlot.add(subplot1, 1);
		mainPlot.add(subplot2, 1);
		mainPlot.add(subplot3, 1);
		mainPlot.setOrientation(PlotOrientation.VERTICAL);
		
		final JFreeChart chart = new JFreeChart(
				"",
				JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true
				);
		
		chart.setBackgroundPaint(Color.white);
		final XYPlot plot = chart.getXYPlot();
		//plot.setBackgroundPaint(Color.lightGray);
		plot.setDomainGridlinePaint(Color.white);
		plot.setRangeGridlinePaint(Color.white);
		plot.setDomainCrosshairVisible(true);
		plot.setRangeCrosshairVisible(false);
		
		setRenderer(subplot1);
		setRenderer(subplot2);
		setRenderer(subplot3);
		
        final DateAxis domainAxis = (DateAxis) mainPlot.getDomainAxis();
        domainAxis.setDateFormatOverride(new SimpleDateFormat("hh:mma"));

		ChartPanel chartPanel = new ChartPanel(chart);
		//chartPanel.setPreferredSize(new Dimension(785, 440));
		chartPanel.setMouseWheelEnabled(true);
		return chartPanel;
	}
	
	private void setRenderer(XYPlot plot) {
		final XYItemRenderer renderer = plot.getRenderer();
		
		if (renderer instanceof StandardXYItemRenderer) {
			final StandardXYItemRenderer itemRenderer = (StandardXYItemRenderer) renderer;
			itemRenderer.setSeriesStroke(0, new BasicStroke(2.0f));
			itemRenderer.setSeriesStroke(1, new BasicStroke(2.0f));
		}
		
        if (renderer instanceof XYLineAndShapeRenderer) {
        	XYLineAndShapeRenderer lineAndShapeRenderer = (XYLineAndShapeRenderer) renderer;
        	//lineAndShapeRenderer.setBaseShapesVisible(true);
        	//lineAndShapeRenderer.setBaseShapesFilled(true);
        	lineAndShapeRenderer.setSeriesShapesVisible(0, true);
        	lineAndShapeRenderer.setSeriesShapesFilled(0, true);
        }
	}

Open in new window

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 47

Expert Comment

by:for_yan
Comment Utility
For me to play I need aself-sufficient code
- this is just part which I cannot compile.

Put System.out.println(something)
within the  if (renderer instanceof XYLineAndShapeRenderer){...  }
to check if it goes there
0
 

Author Comment

by:dshrenik
Comment Utility
I left out the block of code that adds values because I am not allowed to share that code. Moreover, it is dependent on other packages in my project.
0
 

Author Comment

by:dshrenik
Comment Utility
Would it be possible for you to add dummy values to the charts. Sorry if I am asking too much!
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
There is no header part either - class, main() etc.

Just invent some simple data.

First place printout.

And the forst  "if" is working ?

I was looking at the class hierarchy and i don't think
it can be instance of both - maybe i'm not right

0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
No, I think if you put three points in each and add the class and main, etc  - that would be good - you should have beetter idea what kind of
numberss should be there
0
 

Author Comment

by:dshrenik
Comment Utility
Sure. I'll do that.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now