Refine search
DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue( metric, dataType, xLabel ); dataset.addValue( movingAverage, dataType + "(Avg)", xLabel ); true, // tooltips false ); // urls chart.setBackgroundPaint( Color.white ); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint( Color.white ); plot.setForegroundAlpha( 0.5f ); plot.setRangeGridlinesVisible( true ); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); renderer.setSeriesShape( 0, new Ellipse2D.Double( -3.0, -3.0, 6.0, 6.0 ) ); BufferedImage bufferedImage = chart.createBufferedImage( bounds.width, bounds.height ); ImageData imageData = ImageUtil.convertToSWT( bufferedImage );
public CategoryDataset build() { DefaultCategoryDataset ds = new DefaultCategoryDataset(); TreeSet<Row> rowSet = new TreeSet<Row>(rows); TreeSet<Column> colSet = new TreeSet<Column>(columns); Comparable[] _rows = rowSet.toArray(new Comparable[rowSet.size()]); Comparable[] _cols = colSet.toArray(new Comparable[colSet.size()]); // insert rows and columns in the right order for (Comparable r : _rows) ds.setValue(null, r, _cols[0]); for (Comparable c : _cols) ds.setValue(null, _rows[0], c); for( int i=0; i<values.size(); i++ ) ds.addValue( values.get(i), rows.get(i), columns.get(i) ); return ds; } }
/** * Creates a {@link DefaultCategoryDataset} for rendering a graph from a set of {@link MultiStageTimeSeries}. */ protected DefaultCategoryDataset createDataset() { float[][] dataPoints = new float[series.size()][]; for (int i = 0; i < series.size(); i++) dataPoints[i] = series.get(i).pick(timeScale).getHistory(); int dataLength = dataPoints[0].length; for (float[] dataPoint : dataPoints) assert dataLength ==dataPoint.length; DefaultCategoryDataset ds = new DefaultCategoryDataset(); DateFormat format = timeScale.createDateFormat(); Date dt = new Date(System.currentTimeMillis()-timeScale.tick*dataLength); for (int i = dataLength-1; i>=0; i--) { dt = new Date(dt.getTime()+timeScale.tick); String l = format.format(dt); for(int j=0; j<dataPoints.length; j++) ds.addValue(dataPoints[j][i],series.get(j).title.toString(),l); } return ds; }
private void writeBestScoreSummaryChart() { // Each scoreLevel has its own dataset and chartFile List<DefaultCategoryDataset> datasetList = new ArrayList<>(CHARTED_SCORE_LEVEL_SIZE); for (SolverBenchmarkResult solverBenchmarkResult : plannerBenchmarkResult.getSolverBenchmarkResultList()) { String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix(); for (SingleBenchmarkResult singleBenchmarkResult : solverBenchmarkResult.getSingleBenchmarkResultList()) { String problemLabel = singleBenchmarkResult.getProblemBenchmarkResult().getName(); if (singleBenchmarkResult.hasAllSuccess()) { double[] levelValues = ScoreUtils.extractLevelDoubles(singleBenchmarkResult.getAverageScore()); for (int i = 0; i < levelValues.length && i < CHARTED_SCORE_LEVEL_SIZE; i++) { if (i >= datasetList.size()) { datasetList.add(new DefaultCategoryDataset()); } datasetList.get(i).addValue(levelValues[i], solverLabel, problemLabel); } } } } bestScoreSummaryChartFileList = new ArrayList<>(datasetList.size()); int scoreLevelIndex = 0; for (DefaultCategoryDataset dataset : datasetList) { String scoreLevelLabel = plannerBenchmarkResult.findScoreLevelLabel(scoreLevelIndex); CategoryPlot plot = createBarChartPlot(dataset, "Best " + scoreLevelLabel, NumberFormat.getInstance(locale)); JFreeChart chart = new JFreeChart("Best " + scoreLevelLabel + " summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); bestScoreSummaryChartFileList.add(writeChartToImageFile(chart, "bestScoreSummaryLevel" + scoreLevelIndex)); scoreLevelIndex++; } }
@Override public JFreeChart createChart(final int nbr) { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset0.addValue(meanNormRelError[h], "Mean norm rel error", Integer.toString(h + 1)); dataset1.addValue(meanBias[h], "Mean bias", Integer.toString(h + 1)); false // URLs? ); CategoryPlot plot = this.chart_.getCategoryPlot(); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, dataset1); plot.mapDatasetToRangeAxis(1, 1);
public class LabelledBarChartTest { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(10.0, "Series", new Integer(2010)); dataset.addValue(20.0, "Series", new Integer(2011)); dataset.addValue(30.0, "Series", new Integer(2012)); JFreeChart chart = ChartFactory.createBarChart(null,null,null,dataset, PlotOrientation.VERTICAL,true,true,false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); // label the points NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2); CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator( StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); frame.setContentPane(new ChartPanel(chart)); frame.pack(); frame.setVisible(true); } }
DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (String chartValue : chartValues.keySet()) { dataset.setValue(chartValues.get(chartValue), "Completion", chartValue); PlotOrientation.HORIZONTAL, false, false, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0, 20, 0, 20)); plot.getRangeAxis().setRange(0.0, aMaxValue); ((NumberAxis) plot.getRangeAxis()).setNumberFormatOverride(new DecimalFormat("0")); chart.getCategoryPlot().setRenderer(renderer);
DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Integer series : data.keySet()) { for (Integer category : data.get(series).keySet()) { if (map != null && map.containsKey(concept)) { created = true; dataset.addValue(map.get(concept), series, category); } else { dataset.addValue(0, series, category); CategoryPlot plot = new CategoryPlot(); plot.setDataset(dataset); plot.setDomainAxis(domainAxis); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBorderVisible(true); int width = 20 + dataset.getColumnCount() * dataset.getRowCount() * 10; if (width < targMax) image = chart.createBufferedImage(width, targMax);
protected void displayChart(final DCTable table, final DisplayChartCallback displayChartCallback) { final int rowCount = table.getRowCount(); logger.info("Rendering chart with {} patterns", rowCount); final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < rowCount; i++) { final Object expressionObject = table.getValueAt(i, 0); final String expression = extractString(expressionObject); final Object countObject = table.getValueAt(i, 1); final String countString = extractString(countObject); final int count = Integer.parseInt(countString); dataset.addValue(count, expression, ""); } // only show legend if there are not too many patterns final boolean showLegend = dataset.getRowCount() < 25; final JFreeChart chart = ChartFactory .createBarChart("", "", "Match count", dataset, PlotOrientation.VERTICAL, showLegend, true, false); ChartUtils.applyStyles(chart); final ChartPanel chartPanel = ChartUtils.createPanel(chart, true); displayChartCallback.displayChart(chartPanel); }
DefaultCategoryDataset ds = new DefaultCategoryDataset(); ds.addValue(100, "A", "A"); ds.addValue(200, "A", "B"); ds.addValue(400, "A", "C"); ds.addValue(500, "A", "D"); ds.addValue(2000, "A", "E"); CategoryPlot topPlot = bcTop.getCategoryPlot(); NumberAxis topAxis = (NumberAxis) topPlot.getRangeAxis(); topAxis.setLowerBound(1500); topAxis.setUpperBound(2000); CategoryPlot mainPlot = bc.getCategoryPlot(); combinedPlot.add(mainPlot, 5); NumberAxis mainAxis = (NumberAxis) mainPlot.getRangeAxis();; mainAxis.setLowerBound(0); mainAxis.setUpperBound(600);
java.awt.EventQueue.invokeLater(() -> { DefaultCategoryDataset barchartdata = new DefaultCategoryDataset(); barchartdata.setValue(100000, "", "Name"); barchartdata.setValue(200000, "", "Name"); barchartdata.setValue(500000, "", "Name"); JFreeChart barChart = ChartFactory.createAreaChart("Instructor Name", "", "", barchartdata, PlotOrientation.VERTICAL, true, true, true); CategoryPlot barchrt = barChart.getCategoryPlot(); barchrt.setRangeGridlinePaint(Color.ORANGE); ChartPanel barPanel = new ChartPanel(barChart); JPanel jPanel11 = new JPanel(); jPanel11.removeAll(); jPanel11.add(barPanel, BorderLayout.CENTER); jPanel11.validate(); JFrame frame = new JFrame(); frame.add(jPanel11); frame.pack(); frame.setVisible(true); });
/** * Creates a new BarChart with the specified category-labels. * * @param title * @param xAxisLabel * @param yAxisLabel * @param categories */ public StackedBarChart(final String title, final String xAxisLabel, final String yAxisLabel, final String[] categories) { super(title, xAxisLabel, yAxisLabel); this.dataset = new DefaultCategoryDataset(); this.chart = createChart(title, xAxisLabel, yAxisLabel, this.dataset); this.plot = this.chart.getCategoryPlot(); this.categories = categories.clone(); addDefaultFormatting(); // leave a gap of 20% between categories (groups of bars) final CategoryAxis axis1 = this.plot.getDomainAxis(); axis1.setCategoryMargin(0.20); // leave a gap of 10% between individual bars within one category BarRenderer renderer = (BarRenderer)this.plot.getRenderer(); renderer.setItemMargin(0.10); }
int hist[]=new int[11]; int val[]=new int[11]; for(int ii=0;ii<11;ii++) hist[ii]=ii-5;//to get negative indeces I used an array to save them for(int kk=0;kk<coeff.length;kk++) if(coeff[kk]<=5 &coeff[kk]>=-5) val[coeff[kk]+5]++; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for(int ii=0;ii<hist.length;ii++) dataset.setValue(val[ii], "Coefficient value",""+hist[ii]); JFreeChart chart = ChartFactory.createBarChart("Original Histogram", "Coefficient value", "", dataset, PlotOrientation.VERTICAL, false,true, false); //chart.setBackgroundPaint(Color.yellow); chart.getTitle().setPaint(Color.blue); CategoryPlot p = chart.getCategoryPlot(); p.setOutlinePaint(Color.BLUE); p.setRangeGridlinePaint(Color.blue); orgim=chart.createBufferedImage(400,400); Image im1= orgim.getScaledInstance(jLabel12.getWidth(),jLabel12.getHeight(),1); jLabel12.setIcon(new ImageIcon(im1)); ///
//Mock data DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int[] times = new int[]{1,2,3,4,5,6,7,8,9}; for ( int i = 0; i < times.length; i++ ){ dataset.addValue(times[i], "Time", "Hour" + String.valueOf(i+1)); } //create the plot CategoryPlot plot = new CategoryPlot(); //add the first dataset, and render as bar values CategoryItemRenderer renderer = new BarRenderer(); plot.setDataset(0,dataset); plot.setRenderer(0,renderer); //add the second dataset, render as lines CategoryItemRenderer renderer2 = new LineAndShapeRenderer(); plot.setDataset(1, dataset); plot.setRenderer(1, renderer2); //set axis plot.setDomainAxis(new CategoryAxis("Time")); plot.setRangeAxis(new NumberAxis("Value"));
JFrame f = new JFrame("Test"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(24, "Major", "Mathematics"); dataset.setValue(20, "Major", "Philosophy"); dataset.setValue(18, "Major", "Chemical Engineering"); dataset.setValue(15, "Major", "Sociology"); dataset.setValue(14, "Major", "Stuff"); dataset.setValue(13, "Major", "A Program"); dataset.setValue(13, "Major", "Bleg"); JFreeChart chart = ChartFactory.createBarChart("Title", "Major", "Score", dataset, PlotOrientation.HORIZONTAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); Font font1 = new Font("Dialog", Font.PLAIN, 25); Font font2 = new Font("Dialog", Font.PLAIN, 15); Font font3 = new Font("Dialog", Font.PLAIN, 25); plot.getDomainAxis().setLabelFont(font3); plot.getRangeAxis().setLabelFont(font3); CategoryAxis axisDomain = plot.getDomainAxis(); axisDomain.setTickLabelFont(font1); ValueAxis axisRange = plot.getRangeAxis(); axisRange.setTickLabelFont(font2); chart.setAntiAlias(true); f.add(new ChartPanel(chart){ @Override
DefaultCategoryDataset dataset= new DefaultCategoryDataset(); dataset.setValue(rs1.getInt("login_count"),"Login Frequency", today_string_date); today.add(Calendar.DATE, -1); CategoryPlot p = chart.getCategoryPlot(); NumberAxis rangeAxis = (NumberAxis) p.getRangeAxis(); BarRenderer renderer = (BarRenderer) p.getRenderer(); DecimalFormat decimalformat1 = new DecimalFormat("##"); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));
@Override public Map<Shape, String> drawObject(Element e, final double x, final double y, final double width, final double height, OutputDevice outputDevice, RenderingContext ctx, final int dotsPerPixel) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); NodeList childNodes = e.getChildNodes(); final Map<String, String> urls = new HashMap<String, String>(); double value = Double.parseDouble(childElement.getAttribute("value")); String url = childElement.getAttribute("url"); dataset.setValue(value, series, categorie); urls.put(series + ":" + categorie, url); ((CategoryPlot) chart1.getPlot()).getRenderer().setDefaultItemURLGenerator(new CategoryURLGenerator() { @Override public String generateURL(CategoryDataset dataset, int series, int category) {
super(applicationTitle); JFreeChart barChart = ChartFactory.createBarChart(chartTitle, "year", "value", createDataset(), PlotOrientation.VERTICAL, true, true, false); CategoryPlot p = barChart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) p.getRenderer(); renderer.setSeriesPaint(0, new Color(255, 0, 102)); renderer.setSeriesPaint(1, new Color(0, 153, 255)); final String y2001 = "2001"; final String y2002 = "2002"; final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(700, apple, y2000); dataset.addValue(550, mango, y2000); dataset.addValue(700, apple, y2001); dataset.addValue(550, mango, y2001); dataset.addValue(720, apple, y2002); dataset.addValue(570, mango, y2002);
/** * renders a BarChart consisting of one series for each specified foiID. * * @param foiIdArray * @param observationCollection * @return */ protected CategoryPlot renderFoiBarChart(String foiID, String timeString, ObservedValueTuple tuple) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue((Double) tuple.getValue(0), foiID, timeString); JFreeChart chart = ChartFactory.createBarChart3D(null, // String title null, // String categoryAxisLabel null, // String valueAxisLabel dataset, // CategoryDataset dataset PlotOrientation.VERTICAL, false, // boolean legend false, // boolean tooltips false // boolean urls ); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); return plot; }
public void updateValues(String seriesName, double value) { if (!lock) { DefaultCategoryDataset dataset = (DefaultCategoryDataset) chart.getCategoryPlot().getDataset(); dataset.addValue(value, seriesName, Integer.valueOf(0)); if (value < lowerBound) { lowerBound = value; } if (value > upperBound) { upperBound = value; } CategoryPlot plot = chart.getCategoryPlot(); plot.getRangeAxis().setLowerBound(lowerBound); plot.getRangeAxis().setUpperBound(upperBound); } }