Solved

JFreeChart: CombinedDomainXYPlot

Posted on 2011-09-27
12
661 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 500 total points
ID: 36712978
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 

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 June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course 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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

688 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