Search in sources :

Example 31 with JFreeChart

use of org.jfree.chart.JFreeChart in project libresonic by Libresonic.

the class UserChartController method createChart.

private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);
    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);
    // Disable bar outlines.
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);
    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);
    chart.setBackgroundPaint(bgColor);
    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);
    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);
    return chart;
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) LogarithmicAxis(org.jfree.chart.axis.LogarithmicAxis)

Example 32 with JFreeChart

use of org.jfree.chart.JFreeChart in project adempiere by adempiere.

the class VChart method createChart.

public void createChart() {
    JFreeChart chart = chartModel.createChart();
    if (chartPanel != null)
        remove(chartPanel);
    chartPanel = new ChartPanel(chart);
    Dimension size = getSize();
    size.height = chartModel.getWinHeight();
    chartPanel.setPreferredSize(size);
    chartPanel.addChartMouseListener(this);
    add(chartPanel, BorderLayout.CENTER);
    this.setMinimumSize(size);
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) Dimension(java.awt.Dimension) JFreeChart(org.jfree.chart.JFreeChart)

Example 33 with JFreeChart

use of org.jfree.chart.JFreeChart in project adempiere by adempiere.

the class VCRP method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
        Timestamp date = null;
        if (dateFrom.getValue() != null)
            date = (Timestamp) dateFrom.getValue();
        int S_Resource_ID = 0;
        if (resource.getValue() != null)
            S_Resource_ID = ((Integer) resource.getValue()).intValue();
        if (date != null && S_Resource_ID != 0) {
            MResource r = MResource.get(Env.getCtx(), S_Resource_ID);
            int uom_id = r.getResourceType().getC_UOM_ID();
            MUOM uom = MUOM.get(Env.getCtx(), uom_id);
            CategoryDataset dataset = null;
            if (uom.isHour()) {
                dataset = createDataset(date, r);
            } else {
                dataset = createWeightDataset(date, r);
            }
            String title = r.getName() != null ? r.getName() : "";
            title = title + " " + r.getDescription() != null ? r.getDescription() : "";
            JFreeChart jfreechart = createChart(dataset, title, uom);
            centerPanel.removeAll();
            chartPanel = new ChartPanel(jfreechart, false);
            centerPanel.add(chartPanel, BorderLayout.CENTER);
            centerPanel.setVisible(true);
            m_frame.pack();
        }
    }
    if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) {
        dispose();
    }
}
Also used : MResource(org.compiere.model.MResource) MUOM(org.compiere.model.MUOM) ChartPanel(org.jfree.chart.ChartPanel) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) Timestamp(java.sql.Timestamp) JFreeChart(org.jfree.chart.JFreeChart)

Example 34 with JFreeChart

use of org.jfree.chart.JFreeChart in project adempiere by adempiere.

the class VCRPDetail method handleActionEvent.

private void handleActionEvent(ActionEvent e) {
    Timestamp df = getDateFrom();
    Timestamp dt = getDateTo();
    MResource r = getResource(resource.getValue());
    if (df != null && dt != null && r != null) {
        model = CRPDatasetFactory.get(df, dt, r);
        JFreeChart jfreechart = createChart(model.getDataset(), getChartTitle(), getSourceUOM(resource.getValue()));
        chartPanel = new ChartPanel(jfreechart, false);
        contentPanel.setLeftComponent(chartPanel);
        JTree tree = model.getTree();
        tree.addMouseListener(new TreeHandler());
        contentPanel.setRightComponent(new JScrollPane(tree));
        popup = createPopup(tree);
        contentPanel.setDividerLocation(0.70);
        contentPanel.setVisible(true);
        contentPanel.validate();
        contentPanel.repaint();
    }
    SwingTool.setCursorsFromParent(m_form.getWindow(), false);
}
Also used : MResource(org.compiere.model.MResource) JScrollPane(javax.swing.JScrollPane) JTree(javax.swing.JTree) ChartPanel(org.jfree.chart.ChartPanel) Timestamp(java.sql.Timestamp) JFreeChart(org.jfree.chart.JFreeChart)

Example 35 with JFreeChart

use of org.jfree.chart.JFreeChart in project adempiere by adempiere.

the class Graph method loadData.

private void loadData() {
    list = builder.loadData();
    JFreeChart chart = builder.createChart(builder.getMGoal().getChartType());
    if (chartPanel != null)
        remove(chartPanel);
    chartPanel = new ChartPanel(chart);
    chartPanel.setSize(getSize());
    chartPanel.addChartMouseListener(this);
    add(chartPanel, BorderLayout.CENTER);
    if (m_userSelection) {
        int AD_Reference_Value_ID = DB.getSQLValue(null, "SELECT AD_Reference_ID FROM AD_Reference WHERE Name = ?", "PA_Goal ChartType");
        MLookupInfo info = MLookupFactory.getLookup_List(Env.getLanguage(Env.getCtx()), AD_Reference_Value_ID);
        MLookup mLookup = new MLookup(info, 0);
        VLookup lookup = new VLookup("ChartType", false, false, true, mLookup);
        lookup.addVetoableChangeListener(new VetoableChangeListener() {

            public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
                Object value = evt.getNewValue();
                if (value == null)
                    return;
                JFreeChart chart = null;
                chart = builder.createChart(value.toString());
                if (chart != null) {
                    if (chartPanel != null)
                        remove(chartPanel);
                    chartPanel = new ChartPanel(chart);
                    chartPanel.setSize(getSize());
                    chartPanel.addChartMouseListener(Graph.this);
                    add(chartPanel, BorderLayout.CENTER);
                    getParent().validate();
                }
            }
        });
        add(lookup, BorderLayout.NORTH);
    }
    this.setMinimumSize(paneldimension);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) MLookupInfo(org.compiere.model.MLookupInfo) PropertyChangeEvent(java.beans.PropertyChangeEvent) ChartPanel(org.jfree.chart.ChartPanel) MLookup(org.compiere.model.MLookup) VLookup(org.compiere.grid.ed.VLookup) VetoableChangeListener(java.beans.VetoableChangeListener) JFreeChart(org.jfree.chart.JFreeChart) Point(java.awt.Point)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)178 XYPlot (org.jfree.chart.plot.XYPlot)40 NumberAxis (org.jfree.chart.axis.NumberAxis)26 Color (java.awt.Color)22 DateAxis (org.jfree.chart.axis.DateAxis)21 DecimalFormat (java.text.DecimalFormat)18 ChartPanel (org.jfree.chart.ChartPanel)17 XYSeries (org.jfree.data.xy.XYSeries)17 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)17 RectangleInsets (org.jfree.ui.RectangleInsets)17 NumberFormat (java.text.NumberFormat)16 CategoryAxis (org.jfree.chart.axis.CategoryAxis)16 CategoryPlot (org.jfree.chart.plot.CategoryPlot)16 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)13 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)13 HashMap (java.util.HashMap)12 ValueAxis (org.jfree.chart.axis.ValueAxis)12 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)11 CategoryDataset (org.jfree.data.category.CategoryDataset)11 Paint (java.awt.Paint)10