Example usage for org.jfree.data.category DefaultCategoryDataset DefaultCategoryDataset

List of usage examples for org.jfree.data.category DefaultCategoryDataset DefaultCategoryDataset

Introduction

In this page you can find the example usage for org.jfree.data.category DefaultCategoryDataset DefaultCategoryDataset.

Prototype

public DefaultCategoryDataset() 

Source Link

Document

Creates a new (empty) dataset.

Usage

From source file:org.mt4jx.components.visibleComponents.widgets.jfreechart.examples.MTJFreeChartExampleScene.java

public MTJFreeChartExampleScene(MTApplication mtApplication, String name) {
    super(mtApplication, name);
    this.setClearColor(new MTColor(0, 0, 96, 255));
    //Show touches
    this.registerGlobalInputProcessor(new CursorTracer(mtApplication, this));

    // Create Example Data
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < 10; i++) {
        dataset.addValue(10 * Math.random(), "MySeries", "T" + i);
    }/* ww  w  .j ava2s . c om*/
    // Create a JFreeChart
    JFreeChart chart1 = ChartFactory.createLineChart("Line Chart", "x axis", "y axis", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    // Put the JFreeChart into a MTJFreeChart wrapper
    MTJFreeChart mtChart1 = new MTJFreeChart(800, 600, mtApplication, chart1);

    // Create another chart
    DefaultPieDataset pds = new DefaultPieDataset();

    pds.setValue("Java", new Double(17.773));
    pds.setValue("C", new Double(15.822));
    pds.setValue("C++", new Double(8.783));
    pds.setValue("PHP", new Double(7.835));
    pds.setValue("Python", new Double(6.265));
    pds.setValue("C#", new Double(6.226));
    pds.setValue("(Visual) Basic", new Double(5.867));
    pds.setValue("Objective-C", new Double(3.011));
    pds.setValue("Perl", new Double(2.857));

    JFreeChart chart2 = ChartFactory.createPieChart3D(
            "Top 10: TIOBE Programming Community Index\nfor January 2011 (www.tiobe.com)", pds, true, true,
            Locale.GERMANY);
    PiePlot3D plot = (PiePlot3D) chart2.getPlot();
    plot.setStartAngle(290);

    MTJFreeChart mtChart2 = new MTJFreeChart(800, 600, mtApplication, chart2);
    // enable redraw of the chart when it's scaled by the user
    mtChart2.setRedrawWhenScaled(true);
    this.getCanvas().addChild(mtChart1);
    this.getCanvas().addChild(mtChart2);
    mtChart1.setPositionGlobal(new Vector3D(mtApplication.width / 2f, mtApplication.height / 2f));
    mtChart2.setPositionGlobal(new Vector3D(150 + mtApplication.width / 2f, 150 + mtApplication.height / 2f));
}

From source file:sas.BarChart.java

public static CategoryDataset createSaleDataset(java.util.HashMap<String, Float> lsh) {
    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    for (String sh : lsh.keySet()) {
        defaultcategorydataset.addValue(lsh.get(sh), "Sales", sh);
    }//www  .  j ava 2 s  .  co m

    return defaultcategorydataset;
}

From source file:support.TradingVolumeGui.java

private void startGui() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    CategoryPlot chartFrame = createChartFrame(dataset);
    ValueAxis yAxis = chartFrame.getRangeAxis();

    long[] topY = { INITIAL_TOP_Y };
    EntryUpdatedListener<String, Long> entryUpdatedListener = event -> {
        EventQueue.invokeLater(() -> {
            dataset.addValue(event.getValue(), event.getKey(), "");
            topY[0] = max(topY[0], INITIAL_TOP_Y * (1 + event.getValue() / INITIAL_TOP_Y));
            yAxis.setRange(0, topY[0]);/*  www  .j  a v a2 s .  c om*/
        });
    };
    entryListenerId = hzMap.addEntryListener(entryUpdatedListener, true);
}

From source file:ChartUsingJava.CombinedCategoryPlotDemo1.java

/**
 * Creates a dataset.//from   www . j  av a 2 s  .  c o m
 *
 * @return A dataset.
 */
public static CategoryDataset createDataset1() {
    DefaultCategoryDataset result = new DefaultCategoryDataset();
    String series1 = "First";
    String series2 = "Second";
    String type1 = "Type 1";
    String type2 = "Type 2";
    String type3 = "Type 3";
    String type4 = "Type 4";
    String type5 = "Type 5";
    String type6 = "Type 6";
    String type7 = "Type 7";
    String type8 = "Type 8";

    result.addValue(1.0, series1, type1);
    result.addValue(4.0, series1, type2);
    result.addValue(3.0, series1, type3);
    result.addValue(5.0, series1, type4);
    result.addValue(5.0, series1, type5);
    result.addValue(7.0, series1, type6);
    result.addValue(7.0, series1, type7);
    result.addValue(8.0, series1, type8);

    result.addValue(5.0, series2, type1);
    result.addValue(7.0, series2, type2);
    result.addValue(6.0, series2, type3);
    result.addValue(8.0, series2, type4);
    result.addValue(4.0, series2, type5);
    result.addValue(4.0, series2, type6);
    result.addValue(2.0, series2, type7);
    result.addValue(1.0, series2, type8);

    return result;
}

From source file:edu.cuny.cat.ui.ChargePlotPanel.java

public ChargePlotPanel() {

    registry = GameController.getInstance().getRegistry();

    setTitledBorder("Charges");

    dataset = new DefaultCategoryDataset();

    final JFreeChart chart = ChartFactory.createBarChart("", "", "", dataset, PlotOrientation.HORIZONTAL, true,
            true, false);//from www  .  j  a  v  a2 s  . c om
    // chart.setAntiAlias(false);
    chart.setBackgroundPaint(getBackground());
    categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    final BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    UIUtils.setDefaultBarRendererStyle(barrenderer);
    barrenderer.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("Tooltip: {0}"));

    categoryplot.setRowRenderingOrder(SortOrder.DESCENDING);
    final ChartPanel chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:org.miloss.fgsms.services.rs.impl.reports.ws.InvocationsByServiceByMethod.java

@Override
public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files,
        TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx)
        throws IOException {

    Connection con = Utility.getPerformanceDBConnection();
    try {/*from   www .j a  v a 2s. c o  m*/
        PreparedStatement cmd = null;
        ResultSet rs = null;
        DefaultCategoryDataset set = new DefaultCategoryDataset();
        JFreeChart chart = null;

        data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>");
        data.append("This represents the invocations for each service by method (action).<br />");
        data.append(
                "<table class=\"table table-hover\"><tr><th>URL</th><th>Action</th><th>Invocations</th></tr>");
        for (int i = 0; i < urls.size(); i++) {
            if (!isPolicyTypeOf(urls.get(i), PolicyType.TRANSACTIONAL)) {
                continue;
            }
            //https://github.com/mil-oss/fgsms/issues/112
            if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) {
                continue;
            }
            String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i)));
            List<String> actions = getSoapActions(urls.get(i), con);

            for (int k = 0; k < actions.size(); k++) {

                long count = 0;
                try {
                    cmd = con.prepareStatement("select count(*) from RawData where URI=? and "
                            + "(UTCdatetime > ?) and (UTCdatetime < ?) and soapaction=?;");
                    cmd.setString(1, urls.get(i));
                    cmd.setLong(2, range.getStart().getTimeInMillis());
                    cmd.setLong(3, range.getEnd().getTimeInMillis());
                    cmd.setString(4, actions.get(k));

                    rs = cmd.executeQuery();

                    if (rs.next()) {
                        count = rs.getLong(1);
                    }

                } catch (Exception ex) {
                    log.log(Level.WARN, null, ex);
                } finally {
                    DBUtils.safeClose(rs);
                    DBUtils.safeClose(cmd);
                }

                data.append("<tr><td>").append(url).append("</td><td>");
                data.append(Utility.encodeHTML(actions.get(k))).append("</td><td>").append(count + "")
                        .append("</td></tr>");
                if (count > 0) {
                    set.addValue(count, actions.get(k), url);
                }
            }
        }
        data.append("</table>");
        chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Service URL", "", set,
                PlotOrientation.HORIZONTAL, true, false, false);

        try {
            ChartUtilities.saveChartAsPNG(new File(
                    path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart,
                    1500, pixelHeightCalc(set.getRowCount()));
        } catch (IOException ex) {
            log.log(Level.ERROR, "Error saving chart image for request", ex);
        }

        data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">");
        files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png");
    } catch (Exception ex) {
        log.log(Level.ERROR, null, ex);
    } finally {
        DBUtils.safeClose(con);
    }
}

From source file:overTrial.CreateGraphOverTrial.java

private DefaultCategoryDataset createDataset() {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (LinkedList<String> lineData : this.pressureData) {
        dataset.addValue(Double.parseDouble(lineData.get(this.sensorNumber)), "pressure", lineData.get(2));
    }/*from  w  w  w  .  j  a v  a2s. c om*/
    return dataset;
}

From source file:utils.ChartUtils.java

/**
 * Update IR bar chart/*from   w w  w  .j a  va2  s . c  om*/
 * 
 * @param labelsByFrequency Labels ordered by frequency
 * @param IR Imbalance Ratio values
 * @param cp CategoryPlot
 */
public static void updateIRBarChart(ImbalancedFeature[] labelsByFrequency, double[] IR, CategoryPlot cp) {
    DefaultCategoryDataset myData = new DefaultCategoryDataset();

    double prob = 0;

    labelsByFrequency = MetricUtils.sortByFrequency(labelsByFrequency);

    double sum = 0.0;
    for (int i = labelsByFrequency.length - 1; i >= 0; i--) {
        prob = IR[i];
        sum += prob;
        myData.setValue(prob, labelsByFrequency[i].getName(), " ");
    }

    cp.setDataset(myData);

    // add mean mark
    sum = sum / labelsByFrequency.length;
    Marker meanMark = new ValueMarker(sum);
    meanMark.setPaint(Color.red);
    meanMark.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
    meanMark.setLabel("                        Mean: " + MetricUtils.truncateValue(sum, 3));
    cp.addRangeMarker(meanMark);

    //Add Imbalance limit mark
    Marker limitMark = new ValueMarker(1.5);
    limitMark.setPaint(Color.black);
    limitMark.setLabelFont(new Font("SansSerif", Font.BOLD, 12));

    if ((sum < 1.3) || (sum > 1.7)) {
        limitMark.setLabel("                                                Imbalance limit (IR=1.5)");
    }
    cp.addRangeMarker(limitMark);
}

From source file:com.js.quickestquail.ui.stats.YearStat.java

private CategoryDataset generateDataset() {
    Map<Integer, Integer> yearFrequency = new HashMap<>();
    for (String id : DriveManager.get().getSelected().values()) {
        Movie mov = CachedMovieProvider.get().getMovieByID(id);
        int year = mov.getYear();

        if (!yearFrequency.containsKey(year)) {
            yearFrequency.put(year, 1);/*from   www.  jav  a  2  s .  c  om*/
        } else {
            yearFrequency.put(year, yearFrequency.get(year) + 1);
        }

    }

    List<Entry<Integer, Integer>> entries = new ArrayList<>(yearFrequency.entrySet());
    java.util.Collections.sort(entries, new Comparator<Entry<Integer, Integer>>() {
        @Override
        public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2) {
            return o1.getKey().compareTo(o2.getKey());
        }
    });

    // convert to proper format
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (Entry<Integer, Integer> en : entries) {
        dataset.addValue(en.getValue(),
                java.util.ResourceBundle.getBundle("i18n/i18n").getString("stat.year.xaxis"), en.getKey());
    }

    // return
    return dataset;
}

From source file:org.jboss.weld.benchmark.charts.Chart.java

public Chart(String name, String xAxisName, String yAxisName) {
    this.NAME = toCamelCase(name);
    this.Y_AXIS_NAME = toCamelCase(yAxisName);
    this.X_AXIS_NAME = toCamelCase(xAxisName);
    lineChartDataset = new DefaultCategoryDataset();
}