Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Open Source Projects
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide
this week in the
Programmer Certification
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Other Open Source Projects
Create JFreeChart with Stacked Area and Stacked Bar Combination
Steve Dyke
Ranch Hand
Posts: 2278
2
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have the following class I use to create a chart. My problem is instead of having two sets of stacked bars all four bars are stacked on top of each other.
What am I doing wrong?
public class ResourceActivityBarChart { public JFreeChart chart; public String[][] xlabelarray; public String chartTitle; public String[][] dataarray; public String[][] dataarray2; public String[][] dataarray3; public String[][] temp; public int dataarraycounter; public int dataarraycounter2; public int dataarraycounter3; private CategoryDataset dataset; private CategoryDataset dataset2; private CategoryDataset dataset3; private String ls; public ResourceActivityBarChart(){ AS400LibraryStrings lString = new AS400LibraryStrings(); this.ls = lString.getProduction(); } public void setResourceActivityChart(Connection conn, int inspectionarea, int facility, int shift, String[][] xLabelAray){ this.chartTitle = charttitle(conn, inspectionarea, facility, shift); this.xlabelarray = xLabelAray; this.dataset = createDataset(conn, xLabelAray, this.ls); this.dataset2 = createDataset2(conn, xLabelAray, this.ls); this.dataset3 = createDataset3(conn, xLabelAray, this.ls); this.chart = createChart(dataset); } private JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createStackedAreaChart( "Inspection Throughput for: " + this.chartTitle, // chart title "Date", // domain axis label "No of Lots/Inspections", // range axis label this.dataset, // data PlotOrientation.VERTICAL, // orientation true, // 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 customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); StackedAreaRenderer renderer = (StackedAreaRenderer) plot.getRenderer(); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); for(int x = 0;x<4;x++){ renderer.setSeriesItemLabelFont(x, new Font("Times New Roman",Font.PLAIN,10)); renderer.setSeriesPositiveItemLabelPosition(x, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, 45.0)); } chart.getCategoryPlot().setDataset(1, this.dataset2); chart.getCategoryPlot().setRenderer(1, new StackedBarRenderer()); chart.getCategoryPlot().getRenderer(1).setSeriesItemLabelsVisible(0, true); chart.getCategoryPlot().getRenderer(1).setSeriesItemLabelsVisible(1, true); chart.getCategoryPlot().getRenderer(1).setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); chart.getCategoryPlot().setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); chart.getCategoryPlot().setDataset(2, this.dataset3); chart.getCategoryPlot().setRenderer(2, new StackedBarRenderer()); chart.getCategoryPlot().getRenderer(2).setSeriesItemLabelsVisible(0, true); chart.getCategoryPlot().getRenderer(2).setSeriesItemLabelsVisible(1, true); chart.getCategoryPlot().getRenderer(2).setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); chart.getCategoryPlot().setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; } private CategoryDataset createDataset(Connection conn, String [][] dataArray, String ls) { this.dataarraycounter = 1; this.dataarray = new String[this.dataarraycounter][2]; int rtArray[][] = new int[dataArray.length][2]; for(int i = 0;i<dataArray.length;i++){ RejectionSourceConnection rConn = new RejectionSourceConnection(); rConn.setRejectionTagSourceIndexString(conn); rtArray[i][0] = 0; RDTransactionConnection rdConn = new RDTransactionConnection(); rdConn.setRDTransactionsTotalByDate(conn, dataArray[i][3], dataArray[i][4]); rtArray[i][0] = rdConn.getRDLots(); rtArray[i][1] = 0; MOTransactionConnection moConn = new MOTransactionConnection(); moConn.setMOTransactionsTotalByDate(conn, dataArray[i][3], dataArray[i][4]); rtArray[i][1] = moConn.getMOLots(); } // create the dataset... DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int x = 0; int counter = dataArray.length - 1; for(x=0;x<dataArray.length;x++){ dataset.addValue(rtArray[counter - x][0], "RD Transactions(Lots)", dataArray[counter - x][0]); dataset.addValue(rtArray[counter - x][1], "MO's Received", dataArray[counter - x][0]); } return dataset; } private CategoryDataset createDataset2(Connection conn, String [][] dataArray, String ls) { this.dataarraycounter2 = 1; this.dataarray2 = new String[this.dataarraycounter2][2]; int rtArray[][] = new int[dataArray.length][2]; for(int i = 0;i<dataArray.length;i++){ GetDistributionListConnection gdConn = new GetDistributionListConnection(); gdConn.setGroupList("('FAIinspectors')", conn); String inspectorList = "(" + gdConn.getGroupListStringFormated() + ")"; rtArray[i][0] = 0; SamplingInspectionConnection siConn = new SamplingInspectionConnection(); siConn.setSamplingRecordTotalByDate(conn, dataArray[i][1], dataArray[i][2], inspectorList); rtArray[i][0] = siConn.getSamplingInspectionLots(); rtArray[i][1] = 300;//For Testing } // create the dataset... DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); int x = 0; int counter = dataArray.length - 1; for(x=0;x<dataArray.length;x++){ dataset2.addValue(rtArray[counter - x][0], "Sampling Insp(Accepted)", dataArray[counter - x][0]); dataset2.addValue(rtArray[counter - x][1], "Sampling Insp(Rejected)", dataArray[counter - x][0]); } return dataset2; } private CategoryDataset createDataset3(Connection conn, String [][] dataArray, String ls) { this.dataarraycounter3 = 1; this.dataarray3 = new String[this.dataarraycounter3][2]; int rtArray[][] = new int[dataArray.length][2]; for(int i = 0;i<dataArray.length;i++){ GetDistributionListConnection gdConn = new GetDistributionListConnection(); gdConn.setGroupList("('FAIinspectors')", conn); String inspectorList = "(" + gdConn.getGroupListStringFormated() + ")"; rtArray[i][0] = 0; FAIRecordConnection faiConn = new FAIRecordConnection(); faiConn.setFAIRecordTotalByDate(conn, dataArray[i][1], dataArray[i][2], inspectorList); rtArray[i][0] = faiConn.getFAICount(); rtArray[i][1] = 300; } // create the dataset... DefaultCategoryDataset dataset3 = new DefaultCategoryDataset(); int x = 0; int counter = dataArray.length - 1; for(x=0;x<dataArray.length;x++){ dataset3.addValue(rtArray[counter - x][0], "FAI(Accepted)", dataArray[counter - x][0]); dataset3.addValue(rtArray[counter - x][1], "FAI(Rejected)", dataArray[counter - x][0]); } return dataset3; } private String charttitle(Connection conn, int inspectionareaIndex, int facility, int shift){ this.chartTitle = "(All Inspection Areas - "; String facilityName = "All Facilities - "; String shiftName = "All Shifts)"; if(inspectionareaIndex != 0){ InspectionSourceConnection isConn = new InspectionSourceConnection(); isConn.setInspectionAreaNameByIndex(conn, inspectionareaIndex); this.chartTitle = "(" + isConn.getInspectionAreaName() + " Inspection - "; } if(facility == 1){ facilityName = "Gainesville Facility - "; } else if(facility == 2){ facilityName = "Chihuahua Facility - "; } if(shift == 1){ shiftName = "First Shift)"; } else if(shift == 2){ shiftName = "Second Shift)"; } else if(shift == 3){ shiftName = "Third Shift)"; } this.chartTitle = this.chartTitle+facilityName+shiftName; return this.chartTitle; } private String[][] redimArray(){ if (this.dataarraycounter == this.dataarray.length) { int newSize = 1 + this.dataarray.length; // Size of new array. this.temp = new String[newSize][5]; // The new array. System.arraycopy(this.dataarray, 0, temp, 0, this.dataarray.length); this.dataarray = temp; // Set playerList to refer to new array. } return this.dataarray; } public JFreeChart getChart(){ return this.chart; } public String[][] getDataArray(){ return this.dataarray; } }
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Dollar Symbol at Vertical Bar in StackedBarChar in JFreeChart
Scales on Dual Axis Chart
jfreechart bar chart - show item value
how to write dataset value in chart using CategoryItemRenderer
problem in displaying text in item label in JFreeChart
More...