Exemple #1
1
 /**
  * Updates the data set for both charts with the contents of the supplied Hashtable. The Hashtable
  * is expected to contain the following items:
  *
  * <ul>
  *   <li>down - The number of links currently in a down state
  *   <li>up - The number of links currently in an up state
  *   <li>unknown - The number of links currently in an unknown state
  * </ul>
  *
  * @param linkStats The hashtable containing the entries indicating current link statistics.
  */
 public void updateData(Hashtable<String, Integer> linkStats) {
   dpdCurrentData.insertValue(0, "Link Down", linkStats.get("down"));
   dpdCurrentData.insertValue(1, "Link Up", linkStats.get("up"));
   dpdCurrentData.insertValue(2, "Link State Unknown", linkStats.get("unknown"));
   dcdPreviousData.addValue(
       linkStats.get("down"), "Link Down", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("up"), "Link Up", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("unknown"),
       "Link State Unknown",
       Calendar.getInstance().getTime().toString());
 }
Exemple #2
0
  protected void update() {
    // We have to rebuild the dataset from scratch (deleting and replacing it) because JFreeChart's
    // piechart facility doesn't have a way to move series.  Just like the histogram system: stupid
    // stupid stupid.

    SeriesAttributes[] sa = getSeriesAttributes();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int i = 0; i < sa.length; i++)
      if (sa[i].isPlotVisible()) {
        PieChartSeriesAttributes attributes = (PieChartSeriesAttributes) (sa[i]);

        Object[] elements = attributes.getElements();
        double[] values = null;
        String[] labels = null;
        if (elements != null) {
          HashMap map = convertIntoAmountsAndLabels(elements);
          labels = revisedLabels(map);
          values = amounts(map, labels);
        } else {
          values = attributes.getValues();
          labels = attributes.getLabels();
        }

        UniqueString seriesName = new UniqueString(attributes.getSeriesName());

        for (int j = 0; j < values.length; j++)
          dataset.addValue(values[j], labels[j], seriesName); // ugh
      }

    setSeriesDataset(dataset);
  }
  public String generateBarChart(
      String hitSection, HttpSession session, PrintWriter pw, String courseId, int studentId) {
    /* int groupId=0;
                if (groupName.equals("All")){
                    groupId=0;
                }else{
                     groupId = studStatisticBean.getGroupIdByName(groupName);
    }*/

    String filename = null;
    try {
      //  Retrieve list of WebHits
      StudentsConceptChartDataSet cDataSet =
          new StudentsConceptChartDataSet(studStatisticBean, courseId, studentId);
      ArrayList list = cDataSet.getDataBySection(hitSection);

      //  Throw a custom NoDataException if there is no data
      if (list.size() == 0) {
        System.out.println("No data has been found");
        throw new NoDataException();
      }

      //  Create and populate a CategoryDataset
      Iterator iter = list.listIterator();
      DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
      while (iter.hasNext()) {
        StudentsConceptHit wh = (StudentsConceptHit) iter.next();
        // Comparable c1= Double.parseDouble(wh.getHitDegree());
        dataSet.addValue(
            wh.getHitDegree(),
            "degree of mastery for concept ",
            String.valueOf(wh.getHitConcept()));
      }

      //  Create the chart object
      CategoryAxis categoryAxis = new CategoryAxis("Concepts");
      ValueAxis valueAxis = new NumberAxis("Degree of Mastery");
      valueAxis.setRange(0.0, 6.0);
      categoryAxis.setCategoryLabelPositions(
          new CategoryLabelPositions().createUpRotationLabelPositions(45));
      BarRenderer renderer = new BarRenderer();
      renderer.setDrawBarOutline(true);
      renderer.setItemURLGenerator(
          new StandardCategoryURLGenerator("xy_chart.jsp", "series", "section"));
      StandardCategoryToolTipGenerator scttg = new StandardCategoryToolTipGenerator();

      renderer.setToolTipGenerator(scttg);

      Plot plot = new CategoryPlot(dataSet, categoryAxis, valueAxis, renderer);

      JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
      chart.setBackgroundPaint(java.awt.Color.white);

      //  Write the chart image to the temporary directory
      ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

      filename = ServletUtilities.saveChartAsPNG(chart, 600, 400, info, session);

      //  Write the image map to the PrintWriter
      ChartUtilities.writeImageMap(pw, filename, info);
      pw.flush();

    } catch (NoDataException e) {
      System.out.println(e.toString());
      filename = "public_nodata_500x300.png";
    } catch (Exception e) {
      System.out.println("Exception - " + e.toString());
      e.printStackTrace(System.out);
      filename = "public_error_500x300.png";
    }

    return filename;
  }
Exemple #4
0
 /**
  * Initialises the class and internal logger. Uses the supplied arguments to receive data from the
  * application and add data to the charts dynamically.
  *
  * @param title The title of the charts on display. Whether the displayed data is for <code>new
  *     </code> or <code>old</code> links. That is whether the data is for newly discovered links
  *     or existing (old) links already stored within the database.
  * @param parent The instance of <code>COMPortClient</code> that acts as the data source for the
  *     charts.
  */
 public LinkChart(String title, COMPortClient parent) {
   super("Charts", true, true, true, true);
   super.setLayer(1);
   identifier = title.toLowerCase();
   // Obtain an instance of Logger for the class
   log = LoggerFactory.getLogger(className);
   owner = parent;
   // Setup a hashtable to hold the values for up, down and unknown link states
   Hashtable<String, Integer> linkStats = new Hashtable<String, Integer>();
   if (identifier.equals("old")) {
     this.setTitle("Recognised Link Status on " + owner.getPortName() + ":");
     // Get the current figures from the link table
     linkStats = ((LinkTable) owner.getLinkTable().getModel()).getInitialFigures();
   } else if (identifier.equals("new")) {
     this.setTitle("Discovered Link Status on " + owner.getPortName() + ":");
     linkStats = ((LinkTable) owner.getNewLinkTable().getModel()).getInitialFigures();
   } else {
     // If the identifier was set to something other than old or new then it's not right.
     log.warning("An instance of LinkChart has been created for an unknown purpose.");
     return;
   }
   // Initialise the dataset for the pie chart
   dpdCurrentData = new DefaultPieDataset();
   dpdCurrentData.insertValue(0, "Link Down", linkStats.get("down"));
   dpdCurrentData.insertValue(1, "Link Up", linkStats.get("up"));
   dpdCurrentData.insertValue(2, "Link State Unknown", linkStats.get("unknown"));
   // Initialise the dataset for the line chart
   dcdPreviousData = new DefaultCategoryDataset();
   dcdPreviousData.addValue(
       linkStats.get("down"), "Link Down", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("up"), "Link Up", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("unknown"),
       "Link State Unknown",
       Calendar.getInstance().getTime().toString());
   // Set the variables we need for holding the charts
   JFreeChart jfcCurrentStatus; // This will be displayed as a pie chart
   JFreeChart jfcPreviousStatus; // This will be displayed as a line chart
   ChartPanel cpCurrent; // Chartpanels hold the JFreeChart
   ChartPanel cpPrevious;
   // Use the factory to create the charts
   jfcCurrentStatus =
       ChartFactory.createPieChart("Current Status", dpdCurrentData, true, true, false);
   jfcPreviousStatus =
       ChartFactory.createLineChart(
           "Previous Status",
           "Time received",
           "Number of Links",
           dcdPreviousData,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   // Add them to the chart panels
   cpCurrent = new ChartPanel(jfcCurrentStatus);
   cpPrevious = new ChartPanel(jfcPreviousStatus);
   // Add the chart panels to the content pane
   this.add(cpCurrent, BorderLayout.EAST);
   this.add(cpPrevious, BorderLayout.WEST);
   // Change the layout to show them next to each other
   this.setLayout(new GridLayout(1, 2));
   // Add a listener to the window
   this.addInternalFrameListener(new CloseLinkChart(this));
   log.finest("Adding frame to the desktop");
   // Set the window properties and display it
   Client.getJNWindow().addToDesktop(this);
   this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
   this.setSize(650, 400);
   this.setVisible(true);
   owner.addChartWindow(title, this);
 }