the chart bar dont adjust well the bar (image inside)
the chart bar dont adjust well the bar (image inside)
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!
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!
-
- 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)
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
Re: the chart bar dont adjust well the bar (image inside)
Sorry for the delay. If I put these code it shows me something strange: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);
Re: the chart bar dont adjust well the bar (image inside)
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;
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: the chart bar dont adjust well the bar (image inside)
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?
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?
Re: the chart bar dont adjust well the bar (image inside)
Thanks.
I have two methods. I show you one method. The correct code will be:
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;
}
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: the chart bar dont adjust well the bar (image inside)
Unfortunately, you haven't answered my question. Could you please post an SSCCE?
Re: the chart bar dont adjust well the bar (image inside)
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.
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.