the chart bar dont adjust well the bar (image inside)

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
mmm286
Posts: 9
Joined: Wed Oct 15, 2014 10:02 am
antibot: No, of course not.

the chart bar dont adjust well the bar (image inside)

Post by mmm286 » Wed Oct 22, 2014 9:20 am

Hi,
I'm trying to make a bar chart with XYPlot but dont adjust very well the bar. The first bar is too right and the last one is too left.
Any help please?
Thanks and sorry for my English!


Image

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: the chart bar dont adjust well the bar (image inside)

Post by david.gilbert » Sun Oct 26, 2014 2:47 pm

By default the DateAxis is labelling the start of the day, for your chart it would probably be better if the tick labels were placed in the middle of the time period. You can configure this:

Code: Select all

xAxis = (DateAxis) plot.getDomainAxis();
xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

mmm286
Posts: 9
Joined: Wed Oct 15, 2014 10:02 am
antibot: No, of course not.

Re: the chart bar dont adjust well the bar (image inside)

Post by mmm286 » Mon Nov 17, 2014 7:37 pm

david.gilbert wrote:By default the DateAxis is labelling the start of the day, for your chart it would probably be better if the tick labels were placed in the middle of the time period. You can configure this:

Code: Select all

xAxis = (DateAxis) plot.getDomainAxis();
xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
Sorry for the delay. If I put these code it shows me something strange:
Image

mmm286
Posts: 9
Joined: Wed Oct 15, 2014 10:02 am
antibot: No, of course not.

Re: the chart bar dont adjust well the bar (image inside)

Post by mmm286 » Mon Nov 24, 2014 10:40 am

Nobody ¿? :cry:

mmm286
Posts: 9
Joined: Wed Oct 15, 2014 10:02 am
antibot: No, of course not.

Re: the chart bar dont adjust well the bar (image inside)

Post by mmm286 » Tue Jan 27, 2015 3:42 pm

I put my code:

Code: Select all

JFreeChart jfreechart = ChartFactory.createXYBarChart("Ejecucion de componente", "Dia ", true, "Tiempo Completar", intervalxydataset, PlotOrientation.VERTICAL, false, true, false);

            
                jfreechart.setBackgroundPaint(Color.white);
                XYPlot xyplot = (XYPlot)jfreechart.getPlot();
                xyplot.setBackgroundPaint(Color.lightGray);
                xyplot.setDomainGridlinePaint(Color.white);
                xyplot.setRangeGridlinePaint(Color.white);
                xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
                xyplot.setDomainCrosshairVisible(true);
                xyplot.setRangeCrosshairVisible(true);
                XYBarRenderer xybarrenderer = (XYBarRenderer)xyplot.getRenderer();
                xybarrenderer.setDrawBarOutline(false);
                DateAxis dateaxis = new DateAxis();
                dateaxis = (DateAxis) xyplot.getDomainAxis();
               

                dateaxis.setTickMarkPosition(DateTickMarkPosition.START);
                
                
               
                
                return jfreechart;
                

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: the chart bar dont adjust well the bar (image inside)

Post by paradoxoff » Wed Jan 28, 2015 1:03 pm

Is the different DateTickMarkPosition the only difference between the charts?
One thing I have noted is that the the value range on the x axis is several months for the first chart and only a few hours for the second one. I can´t believe that this comes from the different DateTickMarkPosition.
Are you using an identical dataset for the two charts?

mmm286
Posts: 9
Joined: Wed Oct 15, 2014 10:02 am
antibot: No, of course not.

Re: the chart bar dont adjust well the bar (image inside)

Post by mmm286 » Wed Jan 28, 2015 4:56 pm

Thanks.
I have two methods. I show you one method. The correct code will be:

Code: Select all

		        	
System.out.println("dia-mes-ano es... " + dia + "--" + mes + "--" + ano);
		        	timeseries.add(new Day(dia, mes, ano), ms);
		        	
		        	//dataset.addValue(total, "Row " + b, aInsertar.get(b).getDiaString());
		        }
			    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
			    
                timeseriescollection.addSeries(timeseries);
			    
//			    ChartPanel chartPanel = new ChartPanel(chart, false);		
			    
			    JFreeChart jfreechart = createChart(timeseriescollection);
			    ChartPanel chartPanel = new ChartPanel(jfreechart, false);	
				chartPanel.setPreferredSize(new Dimension(1300, 650));
				chartPanel.setBounds(10, 10, 1300, 650);
				panel.add(chartPanel);						
				ventana.setVisible(true);

	}

private static JFreeChart createChart(IntervalXYDataset intervalxydataset)
        {
                JFreeChart jfreechart = ChartFactory.createXYBarChart("Ejecucion de componente", "Dia ", true, "Tiempo Completar", intervalxydataset, PlotOrientation.VERTICAL, false, true, false);

            
                jfreechart.setBackgroundPaint(Color.white);
                XYPlot xyplot = (XYPlot)jfreechart.getPlot();
                xyplot.setBackgroundPaint(Color.lightGray);
                xyplot.setDomainGridlinePaint(Color.white);
                xyplot.setRangeGridlinePaint(Color.white);
                xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
                xyplot.setDomainCrosshairVisible(true);
                xyplot.setRangeCrosshairVisible(true);
                XYBarRenderer xybarrenderer = (XYBarRenderer)xyplot.getRenderer();
                xybarrenderer.setDrawBarOutline(false);
                DateAxis dateaxis = new DateAxis();
                dateaxis = (DateAxis) xyplot.getDomainAxis();               
                dateaxis.setTickMarkPosition(DateTickMarkPosition.START);
                              
                return jfreechart;
                


        }		
		

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: the chart bar dont adjust well the bar (image inside)

Post by paradoxoff » Wed Jan 28, 2015 8:25 pm

Unfortunately, you haven't answered my question. Could you please post an SSCCE?

mmm286
Posts: 9
Joined: Wed Oct 15, 2014 10:02 am
antibot: No, of course not.

Re: the chart bar dont adjust well the bar (image inside)

Post by mmm286 » Thu Jan 29, 2015 12:27 pm

Thanks,
I dont know the problem. But I remove the method createChart and I include all in my main method and it works.
Many thanks for your help.

Locked