if anyone knows how to create this simple chart and can possibly give me an example that would be amazing.. thanks!
Urgent need of help! How do I make this graph??
Urgent need of help! How do I make this graph??
I left a post earlier but I think I am just too much of a newbie to use the advice...I need a simple 3D bar chart that looks like the picture very soon...we have a deadline in 2 days. I bought the manual and have been searching through posts but haven't found the answer. I want to pass in a bunch of codes that are all related to a weight (i can do this in any way, as long as the chart will work)... i need the chart to look like this:

if anyone knows how to create this simple chart and can possibly give me an example that would be amazing.. thanks!
if anyone knows how to create this simple chart and can possibly give me an example that would be amazing.. thanks!
anyone...?
this has been up here for awhie and no one ahs responded...maybe its impossible? but if you can help that would be amazing
Thanks
Craig
Thanks
Craig
found the answer finally
Hey, thanks if you looked here but didn't know...but what i had to do was create a regular chart and then create my own CustomRenderer. Here is the code:
just the renderer:
private class CustomRenderer extends BarRenderer3D {
/** The colors. */
private Paint[] colors;
/**
* Creates a new renderer.
*
* @param colors the colors.
*/
public CustomRenderer(Paint[] colors) {
this.colors = colors;
}
/**
* Returns the paint for an item. Overrides the default behaviour inherited from
* AbstractSeriesRenderer.
*
* @param row the series.
* @param column the category.
*
* @return The item color.
*/
public Paint getItemPaint(int row, int column) {
return this.colors[column % this.colors.length];
}
}
the whole code:
/**
* Calculates the supply short tons for the selected supply center.
*/
public class SCShortTonBarChartByCommodityCode extends Action {
/**
*
*
*/
public SCShortTonBarChartByCommodityCode() {
putValue(Action.NAME,"Inventory Short Tons by CC");
putValue(Action.LONG_DESCRIPTION, "Create a Bar Graph for Inventory Short Tons by CC");
}
/**
* Overriding classes implement this function that will perform an
* action on the passed in class.
*
* @param object
* @return
*/
public void performAction(Bean bean) throws Exception {
if (bean instanceof SupplyCenter) {
SCBarChart chart = new SCBarChart((SupplyCenter)bean);
chart.setSize(500, 270);
chart.setVisible(true, bean.getDomain().getDomainFrame());
}
}
/*
*
*/
private class SCBarChart extends ManagedPanel {
public SCBarChart(SupplyCenter sc) {
super(sc.getDomain());
CategoryDataset dataset = createDataset(sc);
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart, false);
//chartPanel.setPreferredSize(new Dimension(500, 270));
//setMainComponent(new JScrollPane(chartPanel));
setMainComponent(chartPanel);
}
private CategoryDataset createDataset(SupplyCenter sc) {
DefaultKeyedValues2DDataset dataset = new DefaultKeyedValues2DDataset();
String possibleValues = "234ABCDEFGHJKMRSTUVY";
ArrayList<String> codes = new ArrayList<String>();
for(int i = 0; i < possibleValues.length(); i++) {
codes.add(i, possibleValues.substring(i, (i + 1)));
}
List<Object[]> l = sc.getWeightByCommodityCode();
Iterator iter = l.iterator();
Object[] codeWeight = (Object[]) iter.next();
for (Iterator iterator = codes.iterator(); iterator.hasNext();) {
double tons;
String code = (String) iterator.next();
String compareValue = (String) codeWeight[0];
if (code.equals(compareValue)) {
tons = Double.parseDouble(codeWeight[1].toString());
if (iter.hasNext()) {
codeWeight = (Object[]) iter.next();
}
}
else {
tons = 0;
}
dataset.addValue(tons, "", code);
}
return dataset;
}
/**
* Creates a sample chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private JFreeChart createChart(CategoryDataset dataset) {
// create the chart...
JFreeChart chart = ChartFactory.createBarChart3D(
"Inventory Short Tons by Commodity Code", // chart title
"Commodity", // domain axis label
"Short Tons", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
false, // include legend
true, // tooltips?
false // URLs?
);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
// Set the background color for the chart...
chart.setBackgroundPaint(Color.white);
// Get a reference to the plot for further customization...
CategoryPlot plot = chart.getCategoryPlot();
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setLowerMargin(0);
domainAxis.setUpperMargin(0);
// set the range axis to display integers only...
//NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
//rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.white);
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.black);
plot.setRangeGridlineStroke(new BasicStroke());
BarRenderer3D renderer = new CustomRenderer(
new Paint[] {new Color(1, 1, 180), new Color(255, 255, 100), new Color(170, 17, 89),
new Color(9, 140, 18), new Color(233, 139, 12), new Color(73, 215, 226),
new Color(217, 0, 5), new Color(118, 250, 99), new Color(250, 150, 222), Color.gray}
);
renderer.setItemLabelsVisible(true);
ItemLabelPosition p = new ItemLabelPosition(
ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0
);
renderer.setPositiveItemLabelPosition(p);
plot.setRenderer(renderer);
// change the margin at the top of the range axis...
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setLowerMargin(0.15);
rangeAxis.setUpperMargin(0.15);
return chart;
}
}
private class CustomRenderer extends BarRenderer3D {
/** The colors. */
private Paint[] colors;
/**
* Creates a new renderer.
*
* @param colors the colors.
*/
public CustomRenderer(Paint[] colors) {
this.colors = colors;
}
/**
* Returns the paint for an item. Overrides the default behaviour inherited from
* AbstractSeriesRenderer.
*
* @param row the series.
* @param column the category.
*
* @return The item color.
*/
public Paint getItemPaint(int row, int column) {
return this.colors[column % this.colors.length];
}
}
}
just the renderer:
private class CustomRenderer extends BarRenderer3D {
/** The colors. */
private Paint[] colors;
/**
* Creates a new renderer.
*
* @param colors the colors.
*/
public CustomRenderer(Paint[] colors) {
this.colors = colors;
}
/**
* Returns the paint for an item. Overrides the default behaviour inherited from
* AbstractSeriesRenderer.
*
* @param row the series.
* @param column the category.
*
* @return The item color.
*/
public Paint getItemPaint(int row, int column) {
return this.colors[column % this.colors.length];
}
}
the whole code:
/**
* Calculates the supply short tons for the selected supply center.
*/
public class SCShortTonBarChartByCommodityCode extends Action {
/**
*
*
*/
public SCShortTonBarChartByCommodityCode() {
putValue(Action.NAME,"Inventory Short Tons by CC");
putValue(Action.LONG_DESCRIPTION, "Create a Bar Graph for Inventory Short Tons by CC");
}
/**
* Overriding classes implement this function that will perform an
* action on the passed in class.
*
* @param object
* @return
*/
public void performAction(Bean bean) throws Exception {
if (bean instanceof SupplyCenter) {
SCBarChart chart = new SCBarChart((SupplyCenter)bean);
chart.setSize(500, 270);
chart.setVisible(true, bean.getDomain().getDomainFrame());
}
}
/*
*
*/
private class SCBarChart extends ManagedPanel {
public SCBarChart(SupplyCenter sc) {
super(sc.getDomain());
CategoryDataset dataset = createDataset(sc);
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart, false);
//chartPanel.setPreferredSize(new Dimension(500, 270));
//setMainComponent(new JScrollPane(chartPanel));
setMainComponent(chartPanel);
}
private CategoryDataset createDataset(SupplyCenter sc) {
DefaultKeyedValues2DDataset dataset = new DefaultKeyedValues2DDataset();
String possibleValues = "234ABCDEFGHJKMRSTUVY";
ArrayList<String> codes = new ArrayList<String>();
for(int i = 0; i < possibleValues.length(); i++) {
codes.add(i, possibleValues.substring(i, (i + 1)));
}
List<Object[]> l = sc.getWeightByCommodityCode();
Iterator iter = l.iterator();
Object[] codeWeight = (Object[]) iter.next();
for (Iterator iterator = codes.iterator(); iterator.hasNext();) {
double tons;
String code = (String) iterator.next();
String compareValue = (String) codeWeight[0];
if (code.equals(compareValue)) {
tons = Double.parseDouble(codeWeight[1].toString());
if (iter.hasNext()) {
codeWeight = (Object[]) iter.next();
}
}
else {
tons = 0;
}
dataset.addValue(tons, "", code);
}
return dataset;
}
/**
* Creates a sample chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private JFreeChart createChart(CategoryDataset dataset) {
// create the chart...
JFreeChart chart = ChartFactory.createBarChart3D(
"Inventory Short Tons by Commodity Code", // chart title
"Commodity", // domain axis label
"Short Tons", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
false, // include legend
true, // tooltips?
false // URLs?
);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
// Set the background color for the chart...
chart.setBackgroundPaint(Color.white);
// Get a reference to the plot for further customization...
CategoryPlot plot = chart.getCategoryPlot();
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setLowerMargin(0);
domainAxis.setUpperMargin(0);
// set the range axis to display integers only...
//NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
//rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.white);
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.black);
plot.setRangeGridlineStroke(new BasicStroke());
BarRenderer3D renderer = new CustomRenderer(
new Paint[] {new Color(1, 1, 180), new Color(255, 255, 100), new Color(170, 17, 89),
new Color(9, 140, 18), new Color(233, 139, 12), new Color(73, 215, 226),
new Color(217, 0, 5), new Color(118, 250, 99), new Color(250, 150, 222), Color.gray}
);
renderer.setItemLabelsVisible(true);
ItemLabelPosition p = new ItemLabelPosition(
ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0
);
renderer.setPositiveItemLabelPosition(p);
plot.setRenderer(renderer);
// change the margin at the top of the range axis...
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setLowerMargin(0.15);
rangeAxis.setUpperMargin(0.15);
return chart;
}
}
private class CustomRenderer extends BarRenderer3D {
/** The colors. */
private Paint[] colors;
/**
* Creates a new renderer.
*
* @param colors the colors.
*/
public CustomRenderer(Paint[] colors) {
this.colors = colors;
}
/**
* Returns the paint for an item. Overrides the default behaviour inherited from
* AbstractSeriesRenderer.
*
* @param row the series.
* @param column the category.
*
* @return The item color.
*/
public Paint getItemPaint(int row, int column) {
return this.colors[column % this.colors.length];
}
}
}