Package org.jfree.data.category

Examples of org.jfree.data.category.DefaultCategoryDataset


     * @return filename
     */
    public static String generateBarChart(List data, Output output, HttpSession session, PrintWriter printWriter) throws BadDataForChartException {
        OutputElement outputElement = output.getOutputElement();
        // convert data:
        DefaultCategoryDataset  dataset = createDefaultCategoryDataSet(data);

        boolean showLegend = shouldIShowLegend(data);

        JFreeChart chart = ChartFactory.createBarChart(
                outputElement.getName(),         // chart title
View Full Code Here


        return map.values().size() > 2;
    }

    private static DefaultCategoryDataset createDefaultCategoryDataSet(List data) throws BadDataForChartException {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (Object obj : data) {
            Map result = (Map)obj;
            if (result.values().size() < 2)
                throw new BadDataForChartException("For chart, must have at least two columns of data," +
                        " with the first column having the categories and the other columns having the data ");

            boolean weAreAtTheFirstColumn = true;
            String dataName = "";
            for (Object entryObj : result.entrySet()) {
                Map.Entry entry = (Map.Entry)entryObj;
                Object datum = entry.getValue();
                String columnName = (String)entry.getKey();

                if (weAreAtTheFirstColumn) {
                    if (!(datum instanceof String))
                        throw new BadDataForChartException("First column must be a string, isstead it's " + datum.getClass().toString());
                    dataName = (String)datum;
                    weAreAtTheFirstColumn = false;
                } else {
                    if (!   ((datum instanceof BigDecimal) || (datum instanceof BigInteger)) )
                        throw new BadDataForChartException("Data must be decimal or integer.  Can't plot otherwise.");
                    // add the value to the dataset:
                    dataset.addValue((Number)datum,columnName,dataName);
                }

            }
        }
View Full Code Here

    @Override
    protected DatasetHolder newDatasetHolder()
    {
        return new DatasetHolder()
        {
            final private DefaultCategoryDataset _dataset = new DefaultCategoryDataset();

            @Override
            public void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row)
            {
                String x = row.dimensionAsString(0);
                double y = row.dimensionAsDouble(1);
                _dataset.addValue(y, seriesDefinition.getSeriesLegend(), x);
            }

            @Override
            public void beginSeries(SeriesDefinition seriesDefinition)
            {
View Full Code Here

   * @throws SQLException
   */
  public static JFreeChart createBarChart(List<List<Object>> series, ResultSetMetaData metaData, int numberOfCategories, int column)
      throws SQLException {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    HashMap<String, Integer> map = new HashMap<String, Integer>();
    List<String> stringsInRS = new ArrayList<String>();
    List<Double> extremes = getExtremeNumbers(series.get(0));
    for (Object o : series.get(0)) {
      // Object o = series.gtObject(1);
      if (o instanceof Number) {
        stringsInRS.add(convertToString((Number) o, extremes, numberOfCategories));
      } else if(o != null && o instanceof String)
        stringsInRS.add((String) o);
    }
    /* counting frequency of strings */
    for (String s : stringsInRS) {
      if (map.containsKey(s)) {
        map.put(s, map.get(s) + 1);
      } else {
        map.put(s, new Integer(1));
      }
    }
    Set<String> keys = map.keySet();
    String[] keyArray = keys.toArray(new String[0]);
    Arrays.sort(keyArray);

    for (String key : keyArray) {
      dataset.setValue(map.get(key), "Y", key);
    }

    return ChartFactory.createBarChart("Bar chart", metaData.getColumnName(column + 1), "count", dataset,
        PlotOrientation.VERTICAL, true, true, false);
   
View Full Code Here

    private BSlider messageLengthSlider;
    private BList processorList;

    public OneToMany() {
        super();
        data = new DefaultCategoryDataset();
        ( ( CategoryPlot ) chart.getPlot() ).setDataset( data );
    }
View Full Code Here

     
      
            
      
       //loc in care vor fi inserate datele
       DefaultCategoryDataset barchartdata=new DefaultCategoryDataset();
      
       //datele vor fi inserate in tabel
       try {
  File fXmlFile = new File(filename);
  DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
  Document doc = dBuilder.parse(fXmlFile);
  //optional, but recommended
  //read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
  doc.getDocumentElement().normalize();
  //System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
        /*iau toate elementele cu tagul tara*/
  NodeList nList = doc.getElementsByTagName("tara");
  //System.out.println("----------------------------");
         /*cat timp mai am elemente de citit din xml*/
  for (int temp = 0; temp < nList.getLength(); temp++) {
    Node nNode = nList.item(temp);
    //System.out.println("\nCurrent Element :" + nNode.getNodeName());
    if (nNode.getNodeType() == Node.ELEMENT_NODE) {
      Element eElement = (Element) nNode;
                        String nume_tara=new String(eElement.getAttribute("id"));
                        barchartdata.setValue(Long.parseLong(eElement.getElementsByTagName("populatie").item(0).getTextContent()),nume_tara,nume_tara);
                    
                       
                        //barchartdata.setValue(4000,"donatie3","miercuri");
                       
                       
View Full Code Here

            // creo il dataset
            String[] labels = new String[enters.size()];
            for (int i = 0; i < enters.size(); i++) {
              labels[i] = enters.get(i).toString();
            }
            DefaultCategoryDataset enterDirectionDataset = datasetCreator
                .createDirectionDataset(false, new int[] {},
                    computeReg(entersMatch), labels,
                    "entrati da ");
            // creao il grafico
            ProvenienzaChartCreator enterDirectionFactory = new ProvenienzaChartCreator(
                enterDirectionDataset, "Provenienza sciatori");
            JFreeChart enterDirectionChart = enterDirectionFactory
                .createChart();
            enterDirectionPanel = new ChartPanel(
                enterDirectionChart);
            enterDirectionPanel.setBorder(BorderFactory
                .createLineBorder(Color.RED));
            CategoryPlot cp = enterDirectionChart.getCategoryPlot();

            BarRenderer renderer = (BarRenderer) cp.getRenderer();
            // for (int c = 0; c < matchList.size(); c++) {
            // renderer.setSeriesPaint(c, matchList.get(c)
            // .getColor());
            // }
            enterDirectionPanel.setPreferredSize(new Dimension(400,
                300));
            enterDirectionPanel.setRangeZoomable(false);

            /* DIREZIONI SCIATORI RIPARTITI DA PISTA */

            // calcolo la lista di matchdata radioUscite
            ArrayList<MatchData> exitsMatch = new ArrayList<MatchData>();
            for (Integer id : skierExitMap.keySet())
              exitsMatch.add(computeMatchTokens(id, tokens,
                  skierExitMap.get(id), TOKEN_SIZE));

            // creo il dataset
            labels = new String[exits.size()];
            for (int i = 0; i < exits.size(); i++) {
              labels[i] = exits.get(i).toString();
            }
            DefaultCategoryDataset exitDirectionDataset = datasetCreator
                .createDirectionDataset(false,
                    computeStopped(exitsMatch),
                    computeReg(exitsMatch), labels,
                    "verso ");
            // creao il grafico
            DirectionChartCreator exitDirectionFactory = new DirectionChartCreator(
                exitDirectionDataset,
                "Direzione sciatori ripartiti da pista");
            JFreeChart exitDirectionChart = exitDirectionFactory
                .createChart();

            exitDirectionPanel = new ChartPanel(exitDirectionChart);

            exitDirectionPanel.setPreferredSize(new Dimension(400,
                300));
            exitDirectionPanel.setRangeZoomable(false);

            exitDirectionPanel.setBorder(BorderFactory
                .createLineBorder(Color.RED));

            /* DIREZIONI SCIATORI PROVENDIENTI DA */

            // calcolo la lista di datamatch
            ArrayList<DirectionMatchData> directionmatchlist = new ArrayList<DirectionMatchData>();
            listOfMatch = new ArrayList<ChartPanel>();

            for (DirectionData data : directions) {

              DirectionMatchData direction = new DirectionMatchData();
              direction.setFrom(data.getFrom());
              for (ExitDirectionData extdata : data.getListOfTo()) {
                direction.add(computeMatchTokens(
                    extdata.getTo(), tokens,
                    extdata.getListOfTraks(), TOKEN_SIZE));
              }
              directionmatchlist.add(direction);
            }

            // creo il dataset
            for (DirectionMatchData dirmatch : directionmatchlist) {
              labels = new String[dirmatch.listOfTo.size()];
              for (int i = 0; i < dirmatch.getListOfTo().size(); i++) {
                labels[i] = String.valueOf(dirmatch
                    .getListOfTo().get(i).getId());
              }
              DefaultCategoryDataset directionDataset = datasetCreator
                  .createDirectionDataset(false,
                      computeStopped(dirmatch
                          .getListOfTo()),
                      computeReg(dirmatch.getListOfTo()),
                      labels, "verso ");
View Full Code Here

      int[] stopped, int[][] arr, String[] label, String direzione) {
   
    values = arr;
    this.stopped = stopped;
   
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String[] t = null;
    if (is10)
      t = t_10;
    else
      t = t_5;
    for (int i = 0; i < values.length; i++) {
      for (int j = 0; j < values[i].length; j++) {
        dataset.addValue(values[i][j], direzione + label[i], t[j]);
      }
    }
    for (int j = 0; j < stopped.length; j++) {
      dataset.addValue(stopped[j], "sosta in pista", t[j]);
    }
    return dataset;
  }
View Full Code Here

  }
 
  public DefaultCategoryDataset createSpeedPercentDataset(boolean is10,
      ArrayList<Skier> list) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    double [] speeds = new double[6];
    int count = 6;
    for(int z=5;z>=0;z--){
      speeds[z] = computePercent(list, 10*count);
      dataset.addValue(speeds[z], "Intervalli", perc_time[z]);
      count--;
    }
    double[][] d = new double[1][];
    d[0] = new double[speeds.length];
    for (int i = 0; i < speeds.length; i++) {
View Full Code Here

    }
    return dataset;
  }
  public DefaultCategoryDataset createMaxSpeedPercentDataset(boolean is10,
      ArrayList<Skier> list) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    double [] speeds = new double[6];
    int count = 6;
    for(int z=5;z>=0;z--){
      speeds[z] = computeMaxPercent(list, count);
      dataset.addValue(speeds[z], "Intervalli", perc_time[z]);
      count--;
    }
    double[][] d = new double[1][];
    d[0] = new double[speeds.length];
    for (int i = 0; i < speeds.length; i++) {
View Full Code Here

TOP

Related Classes of org.jfree.data.category.DefaultCategoryDataset

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.