Oh my g-d!
I could not believe it was that simple? Here I was creating my own painter but note that painter may well empower more functionality ultimately but
For now I need to know some basics about the IntervalXYDataset which it seems is really a static version of XYSeriesCollection object such that there are two parameters I still do not understand
I only know it controls the with of the bars in odd 3D ways
int seriesCt=dataset.getSeriesCount();
barWidthAdjust= (DEFAULT_CHART_WIDTH /(dataset.getItemCount(seriesCt-1)+1) -7);
dataset.setIntervalPositionFactor(0.5);
dataset.setIntervalWidth(barWidthAdjust);
It would appear that if I set the interval width about the x axis 1/2 to the left and 1/2 to right of each data point then the length of the intervalWidth should work properly but that does not seem to be the case as I have found
what I get does not look quite right when it graphs as it does in 2D in my painter
Maybe someone can explain this further so it makes some sense???
Barchar Revelation - XYDataset controls the width of Bar???
Re: Barchar Revelation - XYDataset controls the width of Bar
It is the dataset where you find the barchart Width override. Frankly that does not make that much sense - To me I would expect in the chart or XYPlot to see an over ride value there
and the setIntervalPositionFactor(0.5) for centered bar with about each datapoint X (domain) value versus setIntervalPositionFactor(0.0) for left justified and right justified as setIntervalPositionFactor(1.0)
would seem better served as setBarJustification("Center"), setBarJustification("Left") and setBarJustification("Right"); Makes more sense to me
as does SetBarChartBar(xwidth); from the Chart or XYPlot object.
I am not sure I really understand this but the following seemed to work to widen the bars effectively:
int seriesCt=dataset.getSeriesCount();
double xxfactor=(dataset.getDomainUpperBound(true)-dataset.getDomainLowerBound(true))/(dataset.getItemCount(seriesCt-1)+1);
dataset.setIntervalPositionFactor(0.5);
dataset.setIntervalWidth(barWidthAdjust);
What I would love someone explain why for the painter I used the resolution width of the image and subtracted a number to give a small space between the bars when using the painter and here I used upper lower bounds and divided by number of (bars + 1) max out with tiny gap the bars displayed
e.g
int seriesCt=dataset.getSeriesCount();
barWidthAdjust= (DEFAULT_CHART_WIDTH /(dataset.getItemCount(seriesCt-1)+1) -7);
with the painter which does things 2D
versus:
int seriesCt=dataset.getSeriesCount();
double xxfactor=(dataset.getDomainUpperBound(true)-dataset.getDomainLowerBound(true))/(dataset.getItemCount(seriesCt-1)+1);
dataset.setIntervalPositionFactor(0.5);
dataset.setIntervalWidth(barWidthAdjust);
without the painter
Original code with painter:
I will add it in next reply!
and the setIntervalPositionFactor(0.5) for centered bar with about each datapoint X (domain) value versus setIntervalPositionFactor(0.0) for left justified and right justified as setIntervalPositionFactor(1.0)
would seem better served as setBarJustification("Center"), setBarJustification("Left") and setBarJustification("Right"); Makes more sense to me
as does SetBarChartBar(xwidth); from the Chart or XYPlot object.
I am not sure I really understand this but the following seemed to work to widen the bars effectively:
int seriesCt=dataset.getSeriesCount();
double xxfactor=(dataset.getDomainUpperBound(true)-dataset.getDomainLowerBound(true))/(dataset.getItemCount(seriesCt-1)+1);
dataset.setIntervalPositionFactor(0.5);
dataset.setIntervalWidth(barWidthAdjust);
What I would love someone explain why for the painter I used the resolution width of the image and subtracted a number to give a small space between the bars when using the painter and here I used upper lower bounds and divided by number of (bars + 1) max out with tiny gap the bars displayed
e.g
int seriesCt=dataset.getSeriesCount();
barWidthAdjust= (DEFAULT_CHART_WIDTH /(dataset.getItemCount(seriesCt-1)+1) -7);
with the painter which does things 2D
versus:
int seriesCt=dataset.getSeriesCount();
double xxfactor=(dataset.getDomainUpperBound(true)-dataset.getDomainLowerBound(true))/(dataset.getItemCount(seriesCt-1)+1);
dataset.setIntervalPositionFactor(0.5);
dataset.setIntervalWidth(barWidthAdjust);
without the painter
Original code with painter:
I will add it in next reply!
Re: Barchar Revelation - XYDataset controls the width of Bar
private static JFreeChart createBarChart(String title, String legendX, String legendY, IntervalXYDataset dataset){
final JFreeChart chart = ChartFactory.createXYBarChart(
title,
legendX,
false,
legendY,
dataset,
PlotOrientation.VERTICAL,
true,
true,
false
);
XYPlot plot = (XYPlot) chart.getPlot();
int seriesCt=dataset.getSeriesCount();
barWidthAdjust= (DEFAULT_CHART_WIDTH /(dataset.getItemCount(0)+1) -7);
System.out.println("barwidthAdjust=" + barWidthAdjust);
final IntervalMarker target = new IntervalMarker(400.0, 700.0);
System.out.println(plot.getRendererCount());
XYBarRenderer xyrend = (XYBarRenderer) plot.getRenderer();
plot.setOutlineVisible(true);
plot.setOutlinePaint(Color.black);
GradientXYBarPainter painterG =new GradientXYBarPainter() { //0.40, 0.40, 0.20) {
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base, boolean pegShadow) {
System.out.println("wSHADDOW="+ bar.getWidth()+",H="+bar.getHeight());
}
@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base) {
System.out.println("w="+ bar.getWidth()+",H="+bar.getHeight());
renderer.setShadowVisible(false);
// renderer.setSeriesPaint(0, gp0);
// renderer.setSeriesPaint(1, gp1);
// renderer.setSeriesPaint(2, gp2);
g2.setColor(Color.red);
g2.fill3DRect((int) (bar.getX() -(barWidthAdjust/2)), (int) bar.getY(),(int) barWidthAdjust,(int) bar.getHeight(), true);
g2.draw3DRect((int) (bar.getX()-(barWidthAdjust/2)), (int) bar.getY(),(int) (barWidthAdjust),(int) bar.getHeight(),true);
}
};
target.setLabel("Target Range");
target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
target.setLabelAnchor(RectangleAnchor.LEFT);
target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
target.setPaint(new Color(222, 222, 255, 128));
plot.addRangeMarker(target, Layer.BACKGROUND);
xyrend.setBarPainter(painterG);
plot.setRenderer(xyrend);
return chart;
}
final JFreeChart chart = ChartFactory.createXYBarChart(
title,
legendX,
false,
legendY,
dataset,
PlotOrientation.VERTICAL,
true,
true,
false
);
XYPlot plot = (XYPlot) chart.getPlot();
int seriesCt=dataset.getSeriesCount();
barWidthAdjust= (DEFAULT_CHART_WIDTH /(dataset.getItemCount(0)+1) -7);
System.out.println("barwidthAdjust=" + barWidthAdjust);
final IntervalMarker target = new IntervalMarker(400.0, 700.0);
System.out.println(plot.getRendererCount());
XYBarRenderer xyrend = (XYBarRenderer) plot.getRenderer();
plot.setOutlineVisible(true);
plot.setOutlinePaint(Color.black);
GradientXYBarPainter painterG =new GradientXYBarPainter() { //0.40, 0.40, 0.20) {
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base, boolean pegShadow) {
System.out.println("wSHADDOW="+ bar.getWidth()+",H="+bar.getHeight());
}
@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base) {
System.out.println("w="+ bar.getWidth()+",H="+bar.getHeight());
renderer.setShadowVisible(false);
// renderer.setSeriesPaint(0, gp0);
// renderer.setSeriesPaint(1, gp1);
// renderer.setSeriesPaint(2, gp2);
g2.setColor(Color.red);
g2.fill3DRect((int) (bar.getX() -(barWidthAdjust/2)), (int) bar.getY(),(int) barWidthAdjust,(int) bar.getHeight(), true);
g2.draw3DRect((int) (bar.getX()-(barWidthAdjust/2)), (int) bar.getY(),(int) (barWidthAdjust),(int) bar.getHeight(),true);
}
};
target.setLabel("Target Range");
target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
target.setLabelAnchor(RectangleAnchor.LEFT);
target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
target.setPaint(new Color(222, 222, 255, 128));
plot.addRangeMarker(target, Layer.BACKGROUND);
xyrend.setBarPainter(painterG);
plot.setRenderer(xyrend);
return chart;
}
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Barchar Revelation - XYDataset controls the width of Bar
Having such a parameter in the chart or plot object doesn´t make much sense to me, as only some specific charts/plots (XYPlot with an INtervalXYDataset and a suitable renderer) will actually use it.rssx wrote:It is the dataset where you find the barchart Width override. Frankly that does not make that much sense - To me I would expect in the chart or XYPlot to see an over ride value there
and the setIntervalPositionFactor(0.5) for centered bar with about each datapoint X (domain) value versus setIntervalPositionFactor(0.0) for left justified and right justified as setIntervalPositionFactor(1.0)
would seem better served as setBarJustification("Center"), setBarJustification("Left") and setBarJustification("Right"); Makes more sense to me
as does SetBarChartBar(xwidth); from the Chart or XYPlot object.
THough you have scattered your comments across various threads (which does not make it ieasy to follow the discussion), you still seem to be interested in getting the 3D effect to work with your "extended" bar width.
Please have a look at the source of GradientXYBarPainter: The 3D effect is generated by applying a couple of gradients from the series paint to white and back. Your code will produce a gradient-less rectangle with a smaller grey rectangle in the background.