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
Solved

JFreeChart: CombinedDomainXYPlot

Posted on 2011-09-27
12
639 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
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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap bin 2 41
runtime exception 2 42
ejb wildfly example 2 25
What browser will run Java? 7 63
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

829 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