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; } }
protected void setDataSetValue(final String label, final Integer value) { _dataset.setValue(value, label, ""); }
/** * Adds or updates a value in the table and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param value the value. * @param rowKey the row key ({@code null} not permitted). * @param columnKey the column key ({@code null} not permitted). * * @see #getValue(Comparable, Comparable) */ public void setValue(double value, Comparable rowKey, Comparable columnKey) { setValue(new Double(value), rowKey, columnKey); }
/** * Adds or updates a value in the table and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param value the value. * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @see #getValue(Comparable, Comparable) */ public void setValue(double value, Comparable rowKey, Comparable columnKey) { setValue(new Double(value), rowKey, columnKey); }
public class BarChartExample { public static void main(String[] args) { // Create a simple Bar chart DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(6, "Profit", "Jane"); dataset.setValue(7, "Profit", "Tom"); dataset.setValue(8, "Profit", "Jill"); dataset.setValue(5, "Profit", "John"); dataset.setValue(12, "Profit", "Fred"); JFreeChart chart = ChartFactory.createBarChart("Comparison between Salesman", "Salesman", "Profit", dataset, PlotOrientation.VERTICAL, false, true, false); try { ChartUtilities.saveChartAsJPEG(new File("C:\\chart.jpg"), chart, 500, 300); } catch (IOException e) { System.err.println("Problem occurred creating chart."); }}}
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; } }
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; } }
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; } }
/** * Adds the specified value to an existing value in the dataset (if the * existing value is {@code null}, it is treated as if it were 0.0). * * @param value the value. * @param rowKey the row key ({@code null} not permitted). * @param columnKey the column key ({@code null} not permitted). * * @throws UnknownKeyException if either key is not defined in the dataset. */ public void incrementValue(double value, Comparable rowKey, Comparable columnKey) { double existing = 0.0; Number n = getValue(rowKey, columnKey); if (n != null) { existing = n.doubleValue(); } setValue(existing + value, rowKey, columnKey); }
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; } }
public class BarChartExample { public static void main(String[] args) { // Create a simple Bar chart double[] dub = {12.2, 15.4, 18.3, 9.3, 7.7}; //Array String[] student = {"Bob", "Dave", "William", "Boris", "Rick"}; //Array DefaultCategoryDataset dataset = new DefaultCategoryDataset(); //Create dataset for(int i = 0; i < dub.length; i++){ dataset.setValue(dub[i], "Marks", student[i]); //Setting the values } JFreeChart chart = ChartFactory.createBarChart3D("Goal comparison", "Marks", "Students", dataset, PlotOrientation.VERTICAL, false, true, false); //Chart creation try { ChartUtilities.saveChartAsJPEG(new File("D:\\Users\\user2777005\\Desktop\\Barchart.jpg"), chart, 500, 300); } catch (IOException e) { System.err.println("Problem occurred creating chart."); }}}
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); });
/** * Adds the specified value to an existing value in the dataset (if the * existing value is <code>null</code>, it is treated as if it were 0.0). * * @param value the value. * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @throws UnknownKeyException if either key is not defined in the dataset. */ public void incrementValue(double value, Comparable rowKey, Comparable columnKey) { double existing = 0.0; Number n = getValue(rowKey, columnKey); if (n != null) { existing = n.doubleValue(); } setValue(existing + value, rowKey, columnKey); }
public class BarExample { public static void main(String arg[]) throws IOException { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); dataSet.setValue(2, Integer.valueOf(1), Integer.valueOf(5)); dataSet.setValue(7, Integer.valueOf(1), Integer.valueOf(10)); dataSet.setValue(4, Integer.valueOf(1), Integer.valueOf(15)); dataSet.setValue(9, Integer.valueOf(1), Integer.valueOf(20)); dataSet.setValue(6, Integer.valueOf(1), Integer.valueOf(25)); JFreeChart chart = ChartFactory.createBarChart ("Chart", "Number of Days", "Number of ECR", dataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); // Reduce margin between bars plot.getDomainAxis().setCategoryMargin(0.0); // Reduce left and right margin plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setUpperMargin(0.0); FileOutputStream outputStream = new FileOutputStream( new File("chart.png")); ChartUtilities.writeChartAsPNG(outputStream, chart, 1024, 768); } }
/** * transfer a CategoryModel into JFreeChart CategoryDataset. */ private CategoryDataset CategoryModelToCategoryDataset(CategoryModel model) { final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (final Iterator it = model.getKeys().iterator(); it.hasNext();) { final List key = (List) it.next(); Comparable series = (Comparable) key.get(0); Comparable category = (Comparable) key.get(1); Number value = (Number) model.getValue(series, category); dataset.setValue(value, series, category); } return dataset; }
@Override public void setData(DataSet data) { TreeSet rowSet = new TreeSet(data.getRows()); TreeSet colSet = new TreeSet(data.getColumns()); Comparable[] _rows = (Comparable[]) rowSet.toArray(new Comparable[rowSet.size()]); Comparable[] _cols = (Comparable[]) colSet.toArray(new Comparable[colSet.size()]); // insert rows and columns in the right order for (Comparable r : _rows) { dataset.setValue(null, r, _cols[0]); } for (Comparable c : _cols) { dataset.setValue(null, _rows[0], c); } for (int i = 0; i < data.getValues().size(); i++) { dataset.addValue((Number) data.getValues().get(i), (Comparable) data.getRows().get(i), (Comparable) data.getColumns().get(i)); } }
dataset.setValue(rs1.getInt("login_count"),"Login Frequency", today_string_date); today.add(Calendar.DATE, -1);
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)); ///
@Override protected Dataset createDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for(Enumeration<?> items = items().objectEnumerator(); items.hasMoreElements(); ) { Object item = items.nextElement(); Comparable<?> name = (Comparable<?>)NSKeyValueCodingAdditions.Utility.valueForKeyPath(item, nameKey()); Number value = (Number)NSKeyValueCodingAdditions.Utility.valueForKeyPath(item, valueKey()); Comparable<?> category = null; if(categoryKey() != null) { category = (Comparable<?>)NSKeyValueCodingAdditions.Utility.valueForKeyPath(item, categoryKey()); } dataset.setValue(value, name, category); } return dataset; } }
protected void addDefaultBarChart(final DCTable table, final DisplayChartCallback displayChartCallback, final int row, final String measureName) { final ActionListener action = e -> { final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final int columnCount = table.getColumnCount(); for (int j = 1; j < columnCount; j++) { final String textValue = table.getTextValueAt(row, j); final Number value = NumberUtils.createNumber(textValue); dataset.setValue(value, table.getColumnName(j), ""); } final JFreeChart chart = ChartFactory .createBarChart("", "", measureName, dataset, PlotOrientation.VERTICAL, true, true, false); ChartUtils.applyStyles(chart); final ChartPanel chartPanel = ChartUtils.createPanel(chart, true); displayChartCallback.displayChart(chartPanel); }; final DCPanel panel = createActionableValuePanel(measureName, Alignment.LEFT, action, IMAGE_PATH_BAR_CHART); table.setValueAt(panel, row, 0); }