?
Solved

JFreeChart: CombinedDomainXYPlot

Posted on 2011-09-27
12
Medium Priority
?
679 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 47

Expert Comment

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

Author Comment

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

Accepted Solution

by:
for_yan earned 2000 total points
ID: 36712978
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:dshrenik
ID: 36713137
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
ID: 36713163
Maybe you can post your code - I could then try to play with it
0
 

Author Comment

by:dshrenik
ID: 36713186

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
 
LVL 47

Expert Comment

by:for_yan
ID: 36713209
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
ID: 36713214
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
ID: 36713237
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
ID: 36713249
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
ID: 36713350
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
ID: 36713381
Sure. I'll do that.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month13 days, 5 hours left to enroll

777 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