Example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setBaseShapesVisible

List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setBaseShapesVisible

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setBaseShapesVisible.

Prototype

public void setBaseShapesVisible(boolean flag) 

Source Link

Document

Sets the base 'shapes visible' flag and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java

/**
 * ?jfreechart//from   ww  w .  ja  v  a 2 s.c  o  m
 */
public void initChart() {
    ts_LP = new TimeSeries("LowPressure", Millisecond.class);
    ts_HP = new TimeSeries("HighPressure", Millisecond.class);
    ts_humidity = new TimeSeries("Humidity", Millisecond.class);
    ts_temprature = new TimeSeries("Temperature", Millisecond.class);
    ts_time = new TimeSeries("TestTime", Millisecond.class);
    ts_num = new TimeSeries("num", Millisecond.class);
    ts_reserved1 = new TimeSeries("reserved1", Millisecond.class);
    ts_reserved2 = new TimeSeries("reserved2", Millisecond.class);
    ts_reserved3 = new TimeSeries("reserved3", Millisecond.class);
    trcollection = new TimeSeriesCollection(ts_LP);

    trcollection.addSeries(ts_HP);

    trcollection2 = new TimeSeriesCollection(ts_humidity);

    trcollection2.addSeries(ts_temprature);

    //        trcollection2.addSeries(ts_num);
    //        trcollection2.addSeries(ts_time);
    //trcollection2.addSeries(ts_reserved1);
    //trcollection2.addSeries(ts_reserved2);
    //trcollection2.addSeries(ts_reserved3);

    //        timeseriescopylist.add(getTimeSeries(3).createCopy(0, getTimeSeries(3).getItemCount() - 1));
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "Time(s)", "PPM", trcollection,
            true, true, false);
    XYPlot xyplot = jfreechart.getXYPlot();

    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);

    Font fs = new Font("", Font.BOLD, 14);
    Font fs2 = new Font("", Font.BOLD, 12);

    XYLineAndShapeRenderer line0render = (XYLineAndShapeRenderer) xyplot.getRenderer(0);

    Color purple = new Color(139, 0, 255);

    line0render.setSeriesPaint(0, Color.blue);
    line0render.setSeriesPaint(1, Color.green);
    line0render.setSeriesPaint(2, Color.red);
    line0render.setSeriesPaint(3, purple);

    //        line0render.setSeriesPaint(3, Color.ORANGE);
    XYLineAndShapeRenderer line1render = new XYLineAndShapeRenderer();
    Color Rosered = new Color(230, 28, 100);
    line1render.setSeriesPaint(0, Color.cyan);
    line1render.setSeriesPaint(1, Rosered);
    line1render.setSeriesPaint(2, Color.orange);
    line1render.setSeriesPaint(3, Color.yellow);
    line1render.setBaseShapesVisible(false);
    xyplot.setRenderer(1, line1render);

    //??
    ValueAxis valueaxis = xyplot.getDomainAxis();

    //
    valueaxis.setLabelFont(fs);

    //
    valueaxis.setTickLabelFont(fs2);

    ValueAxis valueaxis2 = new NumberAxis("");
    valueaxis2.setLabelFont(fs);
    valueaxis2.setTickLabelFont(fs2);

    xyplot.setRangeAxis(1, valueaxis2);
    xyplot.setDataset(1, trcollection2);
    xyplot.mapDatasetToRangeAxis(1, 1);

    //??
    valueaxis.setAutoRange(true);
    //?? 7days
    //                valueaxis.setFixedAutoRange(604800000D);
    valueaxis = xyplot.getRangeAxis();

    valueaxis.setLabelFont(new Font("", Font.BOLD, 14));
    valueaxis.setLabelPaint(line0render.getSeriesPaint(0));
    valueaxis2.setLabelPaint(line1render.getSeriesPaint(0));

    jfreechart.getTitle().setFont(new Font("", Font.BOLD, 20));//
    jfreechart.getLegend().setItemFont(new Font("", Font.ITALIC, 15));
    xyplot.getRenderer(0).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
            new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
    xyplot.getRenderer(1).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
            new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
    chartPanel = new ChartPanel(jfreechart);

    initChartMenu();
    //        chartPanel.getPopupMenu().add(jmenuitem2);
    //        chartPanel.getPopupMenu().getPopupMenuListeners();

    chartPanel.setSize(950, 620);
    chartPanel.setPreferredSize(new Dimension(950, 620));
    jPanel_Show.add(chartPanel, BorderLayout.CENTER);
}

From source file:net.nosleep.superanalyzer.analysis.views.YearView.java

private void createChart() {

    NumberAxis xAxis = new NumberAxis(Misc.getString("RELEASE_YEAR"));
    xAxis.setAutoRangeIncludesZero(false);

    NumberAxis yAxis = new NumberAxis(Misc.getString("SONG_COUNT"));
    yAxis.setAutoRangeIncludesZero(true);

    xAxis.setNumberFormatOverride(new DecimalFormat("0"));

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot(_dataset, xAxis, yAxis, renderer);

    // create and return the chart panel...
    _chart = new JFreeChart(Misc.getString("RELEASE_YEAR"), JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);

    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4));

    LegendTitle legend = _chart.getLegend();
    legend.setFrame(BlockBorder.NONE);/*from   w  w  w.  j a v a 2  s.co  m*/

    _chart.addSubtitle(HomePanel.createSubtitle(Misc.getString("RELEASE_YEAR_TOOLTIP")));

    XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"),
            new DecimalFormat("0.00"));
    renderer.setToolTipGenerator(generator);

    ChartUtilities.applyCurrentTheme(_chart);

    // format the lines after applying the theme
    renderer.setBaseShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(Color.white);
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0));

    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesOutlineStroke(1, new BasicStroke(2.0f));
    renderer.setSeriesShape(1, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0));

    _chart.setPadding(new RectangleInsets(10, 10, 10, 10));

    Misc.formatChart(plot);
}

From source file:org.tolven.web.MenuAction.java

/**
  * Creates a chart based on MenuData/*  w ww . jav a 2 s  .  c  o  m*/
  * @param dataset  a dataset
  * @return A chart suitable for rendering
  */
public JFreeChart createChart(String title, XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            "Date", // x-axis label
            "Value", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    return chart;
}

From source file:net.liuxuan.device.w3330.JIF_DrawChart_w3330.java

/**
 * ?jfreechart/*from  www  .  ja va2 s.  c  om*/
 */
public void initChart() {
    ts_wppm = new TimeSeries("PPM", Millisecond.class);
    ts_wppm_zero = new TimeSeries("PPM-Zero", Millisecond.class);
    ts_flux = new TimeSeries("Flux", Millisecond.class);
    ts_wvtr = new TimeSeries("WVTR", Millisecond.class);
    ts_tempcell = new TimeSeries(" Cell Temperature", Millisecond.class);
    ts_tempambi = new TimeSeries("Ambient Temperature", Millisecond.class);
    ts_status = new TimeSeries("Status", Millisecond.class);
    ts_fitting = new TimeSeries("fitting curve1", Millisecond.class);
    ts_fitting2 = new TimeSeries("fitting curve2", Millisecond.class);
    trcollection = new TimeSeriesCollection(ts_wppm);

    trcollection.addSeries(ts_wppm_zero);

    trcollection.addSeries(ts_wvtr);

    trcollection.addSeries(ts_fitting2);//ppm
    trcollection2 = new TimeSeriesCollection(ts_flux);

    trcollection2.addSeries(ts_fitting);//temp3

    trcollection2.addSeries(ts_tempcell);

    trcollection2.addSeries(ts_tempambi);

    trcollection2.addSeries(ts_status);
    //        timeseriescopylist.add(getTimeSeries(3).createCopy(0, getTimeSeries(3).getItemCount() - 1));
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "Time(s)", "PPM", trcollection,
            true, true, false);
    XYPlot xyplot = jfreechart.getXYPlot();

    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);

    Font fs = new Font("", Font.BOLD, 14);
    Font fs2 = new Font("", Font.BOLD, 12);

    XYLineAndShapeRenderer line0render = (XYLineAndShapeRenderer) xyplot.getRenderer(0);

    Color purple = new Color(139, 0, 255);

    line0render.setSeriesPaint(0, Color.blue);
    line0render.setSeriesPaint(1, Color.green);
    line0render.setSeriesPaint(2, Color.red);
    line0render.setSeriesPaint(3, purple);

    //        line0render.setSeriesPaint(3, Color.ORANGE);
    XYLineAndShapeRenderer line1render = new XYLineAndShapeRenderer();
    Color Rosered = new Color(230, 28, 100);
    line1render.setSeriesPaint(0, Color.orange);
    line1render.setSeriesPaint(1, Color.yellow);
    line1render.setSeriesPaint(2, Color.cyan);
    line1render.setSeriesPaint(3, Rosered);
    line1render.setBaseShapesVisible(false);
    xyplot.setRenderer(1, line1render);

    //??
    ValueAxis valueaxis = xyplot.getDomainAxis();

    //
    valueaxis.setLabelFont(fs);

    //
    valueaxis.setTickLabelFont(fs2);

    ValueAxis valueaxis2 = new NumberAxis("");
    valueaxis2.setLabelFont(fs);
    valueaxis2.setTickLabelFont(fs2);

    xyplot.setRangeAxis(1, valueaxis2);
    xyplot.setDataset(1, trcollection2);
    xyplot.mapDatasetToRangeAxis(1, 1);

    //??
    valueaxis.setAutoRange(true);
    //?? 7days
    //                valueaxis.setFixedAutoRange(604800000D);
    valueaxis = xyplot.getRangeAxis();

    valueaxis.setLabelFont(new Font("", Font.BOLD, 14));
    valueaxis.setLabelPaint(line0render.getSeriesPaint(0));
    valueaxis2.setLabelPaint(line1render.getSeriesPaint(0));

    jfreechart.getTitle().setFont(new Font("", Font.BOLD, 20));//
    jfreechart.getLegend().setItemFont(new Font("", Font.ITALIC, 15));
    xyplot.getRenderer(0).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
            new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
    xyplot.getRenderer(1).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
            new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
    chartPanel = new ChartPanel(jfreechart);

    initChartMenu();
    //        chartPanel.getPopupMenu().add(jmenuitem2);
    //        chartPanel.getPopupMenu().getPopupMenuListeners();

    chartPanel.setSize(950, 620);
    chartPanel.setPreferredSize(new Dimension(950, 620));
    jPanel_Show.add(chartPanel, BorderLayout.CENTER);
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java

@Override
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    XYDataset dataset = (XYDataset) datasets.getDatasets().get("1");

    final JFreeChart sparkLineGraph = ChartFactory.createTimeSeriesChart(null, null, null, dataset, legend,
            false, false);/*from  w w w  . j a v a  2  s .  c  o m*/
    sparkLineGraph.setBackgroundPaint(color);

    TextTitle title = setStyleTitle(name, styleTitle);
    sparkLineGraph.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        sparkLineGraph.addSubtitle(subTitle);
    }

    sparkLineGraph.setBorderVisible(false);
    sparkLineGraph.setBorderPaint(Color.BLACK);
    XYPlot plot = sparkLineGraph.getXYPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setBackgroundPaint(null);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(color);

    // calculate the last marker color
    Paint colorLast = getLastPointColor();

    // Calculate average, minimum and maximum to draw plot borders.
    boolean isFirst = true;
    double avg = 0, min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY;
    int count = 0;
    for (int i = 0; i < timeSeries.getItemCount(); i++) {
        if (timeSeries.getValue(i) != null) {
            count++;
            if (isFirst) {
                min = timeSeries.getValue(i).doubleValue();
                max = timeSeries.getValue(i).doubleValue();
                isFirst = false;
            }
            double n = timeSeries.getValue(i).doubleValue();
            //calculate avg, min, max
            avg += n;
            if (n < min)
                min = n;
            if (n > max)
                max = n;
        }
    }
    // average
    avg = avg / (double) count;

    // calculate min and max between thresholds!
    boolean isFirst2 = true;
    double lb = 0, ub = 0;
    for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) {
        Double thres = (Double) iterator.next();
        if (isFirst2 == true) {
            ub = thres.doubleValue();
            lb = thres.doubleValue();
            isFirst2 = false;
        }
        if (thres.doubleValue() > ub)
            ub = thres.doubleValue();
        if (thres.doubleValue() < lb)
            lb = thres.doubleValue();
    }

    plot.getRangeAxis().setRange(new Range(Math.min(lb, min - 2), Math.max(ub, max + 2) + 2));

    addMarker(1, avg, Color.GRAY, 0.8f, plot);
    //addAvaregeSeries(series, plot);
    addPointSeries(timeSeries, plot);

    int num = 3;
    for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) {
        Double thres = (Double) iterator.next();
        TargetThreshold targThres = thresholds.get(thres);
        Color color = Color.WHITE;
        if (targThres != null && targThres.getColor() != null) {
            color = targThres.getColor();
        }
        if (targThres.isVisible()) {
            addMarker(num++, thres.doubleValue(), color, 0.5f, plot);
        }
    }

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);
    domainAxis.setUpperMargin(0.2);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(false);

    plot.getRenderer().setSeriesPaint(0, Color.BLACK);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) {
        public boolean getItemShapeVisible(int _series, int item) {
            TimeSeriesDataItem tsdi = timeSeries.getDataItem(item);
            if (tsdi == null)
                return false;
            Month period = (Month) tsdi.getPeriod();
            int currMonth = period.getMonth();
            int currYear = period.getYearValue();
            int lastMonthFilled = lastMonth.getMonth();
            int lastYearFilled = lastMonth.getYearValue();
            boolean isLast = false;
            if (currYear == lastYearFilled && currMonth == lastMonthFilled) {
                isLast = true;
            }
            return isLast;
        }
    };
    renderer.setSeriesPaint(0, Color.decode("0x000000"));

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(colorLast);
    renderer.setBaseOutlinePaint(Color.BLACK);
    renderer.setUseOutlinePaint(true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0));

    if (wlt_mode.doubleValue() == 0) {
        renderer.setBaseItemLabelsVisible(Boolean.FALSE, true);
    } else {
        renderer.setBaseItemLabelsVisible(Boolean.TRUE, true);
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());
        renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("{2}", new DecimalFormat("0.###"),
                new DecimalFormat("0.###")) {
            public String generateLabel(CategoryDataset dataset, int row, int column) {
                if (dataset.getValue(row, column) == null || dataset.getValue(row, column).doubleValue() == 0)
                    return "";
                String columnKey = (String) dataset.getColumnKey(column);
                int separator = columnKey.indexOf('-');
                String month = columnKey.substring(0, separator);
                String year = columnKey.substring(separator + 1);
                int monthNum = Integer.parseInt(month);
                if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) {
                    if (wlt_mode.doubleValue() == 2 && column % 2 == 0)
                        return "";

                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.MONTH, monthNum - 1);
                    SimpleDateFormat dataFormat = new SimpleDateFormat("MMM");
                    return dataFormat.format(calendar.getTime());
                } else
                    return "" + monthNum;
            }
        });
    }

    if (wlt_mode.doubleValue() == 3) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2));

    } else if (wlt_mode.doubleValue() == 4) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4));
    }

    if (legend == true) {
        LegendItemCollection collection = createThresholdLegend(plot);
        LegendItem item = new LegendItem("Avg", "Avg", "Avg", "Avg", new Rectangle(10, 10), colorAverage);
        collection.add(item);
        plot.setFixedLegendItems(collection);

    }

    plot.setRenderer(0, renderer);
    logger.debug("OUT");
    return sparkLineGraph;
}

From source file:userinterface.graph.Graph.java

/**
 * Initialises the GraphModel's series and canvas list. Also starts off the
 * graph update timer (one per chart)./*from   w  w  w  .  ja v  a 2 s .  c o  m*/
 * 
 * @param title
 *            Title of the graph.
 */
public Graph(String title) {
    super(ChartFactory.createXYLineChart(title, "X", "Y", new XYSeriesCollection(), PlotOrientation.VERTICAL,
            true, true, false));

    graphCache = new HashMap<SeriesKey, LinkedList<XYDataItem>>();
    keyToSeries = new HashMap<SeriesKey, XYSeries>();
    keyToGraphSeries = new HashMap<SeriesKey, SeriesSettings>();
    graphTitle = new MultipleLineStringSetting("title", title, "The main title heading for the chart.", this,
            false);
    titleFont = new FontColorSetting("title font",
            new FontColorPair(new Font("SansSerif", Font.PLAIN, 14), Color.black),
            "The font for the chart's title", this, false);
    legendVisible = new BooleanSetting("legend visible?", new Boolean(true),
            "Should the legend, which displays all of the series headings, be displayed?", this, false);

    String[] choices = { "Left", "Right", "Bottom", "Top" };
    legendPosition = new ChoiceSetting("legend position", choices, choices[RIGHT], "The position of the legend",
            this, false);
    legendFont = new FontColorSetting("legend font",
            new FontColorPair(new Font("SansSerif", Font.PLAIN, 11), Color.black), "The font for the legend",
            this, false);

    // Some easy references
    chart = super.getChart();
    plot = chart.getXYPlot();
    plot.setBackgroundPaint((Paint) Color.white);
    seriesCollection = (XYSeriesCollection) plot.getDataset();

    xAxisSettings = new AxisSettings("X", true, this);
    yAxisSettings = new AxisSettings("Y", false, this);

    xAxisSettings.addObserver(this);
    yAxisSettings.addObserver(this);

    displaySettings = new DisplaySettings(this);
    displaySettings.addObserver(this);

    seriesList = new SeriesSettingsList(this);

    // create a regular XY line chart
    XYItemRenderer r = plot.getRenderer();
    // if possible, try to match the old grapher
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
        renderer.setAutoPopulateSeriesPaint(true);
        renderer.setAutoPopulateSeriesShape(true);
    }

    plot.setDrawingSupplier(new DefaultDrawingSupplier(SeriesSettings.DEFAULT_PAINTS,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, SeriesSettings.DEFAULT_SHAPES));

    super.setPopupMenu(null);

    /* Make sure the graph resembles its default settings. */
    updateGraph();

    // schedule a periodic timer for graph updates
    new java.util.Timer().scheduleAtFixedRate(new GraphUpdateTask(), 0, // start now
            updateInterval);
}

From source file:lucee.runtime.tag.Chart.java

private void setMarker(JFreeChart chart, Plot p) {
    if (!showmarkers)
        return;/*  w w  w . j  a  v a  2s .  c  o m*/

    if (markersize < 1 || markersize > 100)
        markersize = 4;

    if (p instanceof XYPlot) {
        XYPlot xyp = (XYPlot) p;
        XYItemRenderer r = xyp.getRenderer();
        if (r instanceof XYLineAndShapeRenderer) {
            XYLineAndShapeRenderer xyr = (XYLineAndShapeRenderer) r;
            xyr.setBaseShapesVisible(true);
            xyr.setBaseShapesFilled(true);

            int seriesCount = _series.size();
            for (int i = 0; i < seriesCount; i++) {
                xyr.setSeriesShapesVisible(i, true);
                xyr.setSeriesItemLabelsVisible(i, true);
                xyr.setSeriesShape(i, ShapeUtilities.createDiamond(markersize));
                xyr.setUseFillPaint(true);
                xyr.setBaseFillPaint(databackgroundcolor);
            }
        }
    } else if (p instanceof CategoryPlot) {
        CategoryPlot cp = (CategoryPlot) p;
        CategoryItemRenderer r = cp.getRenderer();
        if (r instanceof LineAndShapeRenderer) {
            LineAndShapeRenderer lsr = (LineAndShapeRenderer) r;

            int seriesCount = _series.size();
            for (int i = 0; i < seriesCount; i++) {
                lsr.setSeriesShapesVisible(i, true);
                lsr.setSeriesItemLabelsVisible(i, true);
                lsr.setSeriesShape(i, ShapeUtilities.createDiamond(markersize));
                lsr.setUseFillPaint(true);
                lsr.setBaseFillPaint(databackgroundcolor);
            }
        }
    }
}

From source file:edu.ucla.stat.SOCR.applications.demo.StockApplication.java

void updateGraph() {
    //System.out.println("UpdateGraph get called")
    //   System.out.println("S0="+S0+" E="+E+" P="+P);

    calculate(choice);//from  ww  w . j  a  v a 2  s  .  co m

    XYSeriesCollection ds = createDataset(choice);

    JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            xAxis, // x axis label
            yAxis, // y axis label
            ds, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );
    chart.setBackgroundPaint(Color.white);
    XYPlot subplot1 = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) subplot1.getRenderer();

    renderer1.setSeriesPaint(0, Color.red);
    renderer1.setSeriesPaint(1, Color.blue);
    renderer1.setSeriesPaint(2, Color.green);
    renderer1.setSeriesPaint(3, Color.gray);

    /* Shape shape = renderer1.getBaseShape();
     renderer1.setSeriesShape(2, shape);
     renderer1.setSeriesShape(3, shape);*/
    renderer1.setBaseLinesVisible(true);
    renderer1.setBaseShapesVisible(true);
    renderer1.setBaseShapesFilled(true);

    chartPanel = new ChartPanel(chart, false);
    chartPanel.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y));

    upContainer = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(leftPanel),
            new JScrollPane(chartPanel));

    this.getMainPanel().removeAll();
    this.getMainPanel().add(new JScrollPane(upContainer), BorderLayout.CENTER);
    this.getMainPanel().validate();
    //  getRecordTable().setText("Any Explaination goes here.");

    //
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java

/***********************************************************************************************
 * Create a simple Chart from the specified XYDataset.
 * Choose a TimeSeriesChart or a XYLineChart appropriately.
 * Called from createCustomisedChart() in each ChartUIComponent subclass.
 *
 *
 * @param dataset// w w w  .j  av a 2s.  c  o  m
 * @param timezone
 * @param metadatalist
 * @param channelcount
 * @param temperaturechannel
 * @param updatetype
 * @param displaylimit
 * @param channelselector
 * @param debug
 *
 * @return JFreeChart
 */

public static JFreeChart createChart(final XYDataset dataset, final TimeZone timezone,
        final List<Metadata> metadatalist, final int channelcount, final boolean temperaturechannel,
        final DataUpdateType updatetype, final int displaylimit,
        final ChannelSelectorUIComponentInterface channelselector, final boolean debug) {
    final String SOURCE = "ChartHelper.createChart() ";
    final JFreeChart chart;
    final String strTitle;
    final String strLabelX;
    final String strLabelY;
    final XYDataset xyDatasetToDisplay;

    // The set of Metadata available should include the Instrument
    // and any items from the current observation
    strTitle = MetadataHelper.getMetadataValueByKey(metadatalist,
            MetadataDictionary.KEY_OBSERVATION_TITLE.getKey());
    strLabelX = MetadataHelper.getMetadataValueByKey(metadatalist,
            MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_X.getKey());
    // Axis.Y.0 only in this version
    strLabelY = MetadataHelper.getMetadataValueByKey(metadatalist,
            MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey() + MetadataDictionary.SUFFIX_SERIES_ZERO);

    // Transform the XYdataset in accordance with the current ChannelSelection Mode before displaying

    channelselector.debugSelector(debug, SOURCE);

    xyDatasetToDisplay = copyTransformedXYDataset(dataset, timezone, updatetype, displaylimit,
            channelselector.isDecimating(), channelselector.getChannelSelectionModes());
    if (dataset instanceof TimeSeriesCollection) {
        chart = ChartFactory.createTimeSeriesChart(strTitle, strLabelX, strLabelY, xyDatasetToDisplay,
                channelselector.hasLegend(), true, false);
    } else {
        chart = ChartFactory.createXYLineChart(strTitle, strLabelX, strLabelY, xyDatasetToDisplay,
                PlotOrientation.VERTICAL, channelselector.hasLegend(), true, false);
    }

    if ((chart != null) && (chart.getXYPlot() != null) && (chart.getXYPlot().getRangeAxis() != null)) {
        final Stroke strokeCrosshair;
        final XYPlot plot;
        final XYItemRenderer renderer;

        chart.setBackgroundPaint(UIComponentPlugin.DEFAULT_COLOUR_CANVAS.getColor());

        // Experimental chart configuration
        chart.getTitle().setFont(UIComponentPlugin.DEFAULT_FONT.getFont().deriveFont(20.0f));

        plot = chart.getXYPlot();
        plot.setBackgroundPaint(COLOR_PLOT);
        plot.setDomainGridlinePaint(COLOR_GRIDLINES);
        plot.setRangeGridlinePaint(COLOR_GRIDLINES);
        plot.setAxisOffset(PLOT_RECTANGLE_INSETS);

        plot.setDomainCrosshairVisible(true);
        plot.setDomainCrosshairLockedOnData(false);
        plot.setRangeCrosshairVisible(false);

        // Make the Crosshair more visible by changing the width from the default
        strokeCrosshair = new BasicStroke(2.0f, // The width of this BasicStroke
                BasicStroke.CAP_BUTT, // The decoration of the ends of a BasicStroke
                BasicStroke.JOIN_BEVEL, // The decoration applied where path segments meet
                0.0f, // The limit to trim the miter join
                new float[] { 2.0f, 2.0f }, // The array representing the dashing pattern
                0.0f); // The offset to start the dashing pattern
        plot.setDomainCrosshairStroke(strokeCrosshair);

        renderer = plot.getRenderer();

        if ((renderer != null) && (renderer instanceof XYLineAndShapeRenderer)) {
            final XYLineAndShapeRenderer xyItemRenderer;
            int intSeriesCount;

            xyItemRenderer = (XYLineAndShapeRenderer) renderer;

            xyItemRenderer.setBaseLinesVisible(true);
            xyItemRenderer.setBaseShapesVisible(false);
            xyItemRenderer.setBaseShapesFilled(true);
            xyItemRenderer.setItemLabelsVisible(true);

            // Set the shape for the Chart legend items
            ChartUIHelper.setLegendShape(xyItemRenderer);

            // Colour only as many Series as we know about
            intSeriesCount = 0;

            // Examine the state of each channel's selection
            for (int channel = 0; channel < channelcount; channel++) {
                final ChannelSelectionMode selectionMode;

                if ((channelselector.getChannelSelectionModes() != null)
                        && (channelselector.getChannelSelectionModes().size() == channelcount)) {
                    // If there is a ChannelSelector, get the gain setting, or OFF
                    selectionMode = channelselector.getChannelSelectionModes().get(channel);
                } else if (!channelselector.showChannels()) {
                    // If there is no ChannelSelector, we assume that all Channels are ON, at X1
                    selectionMode = ChannelSelectionMode.X1;
                } else {
                    // Not sure what to do, so just show all
                    selectionMode = ChannelSelectionMode.X1;
                }

                if (!ChannelSelectionMode.OFF.equals(selectionMode)) {
                    final ColourInterface colour;

                    colour = MetadataHelper.getChannelColour(metadatalist, channel, temperaturechannel);

                    MetadataHelper.showMetadataList(metadatalist, SOURCE + " COLOURS FOR CHART",
                            LOADER_PROPERTIES.isMetadataDebug());

                    if (colour != null) {
                        // Map the Colour to the Series
                        xyItemRenderer.setSeriesPaint(intSeriesCount, colour.getColor());
                    } else {
                        // Use the default colour if the metadata doesn't have it
                        LOGGER.error(SOURCE
                                + "The channel colour was missing or incorrectly specified in the Metadata, using default colour"
                                + " [channel=" + channel + "]");
                        xyItemRenderer.setSeriesPaint(intSeriesCount,
                                ChartUIHelper.getStandardColour(channel).getColor());
                    }

                    // Prepare for the next Series
                    intSeriesCount++;
                }
            }
        }
    }

    return (chart);
}

From source file:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java

/**
 * Creates a chart./*from  www .ja v  a2 s  .c o  m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
// protected JFreeChart createChart(XYDataset dataset, double[][] polygons, int num_poly) {

protected JFreeChart createChart(XYDataset[] dataset) {
    //System.out.println("createChart get called");
    boolean legend = false;
    /*if (num_series>1&&segment_flag==false)
       legend = true;*/

    //   System.out.println("createchart: inde="+independentVarLength);
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset[0], // data
            PlotOrientation.VERTICAL, legend, // include legend
            true, // tooltips
            false // urls
    );

    //printDataset(dataset, num_series);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot subplot1 = (XYPlot) chart.getPlot();
    subplot1.setBackgroundPaint(Color.lightGray);
    subplot1.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    subplot1.setDomainGridlinePaint(Color.white);
    subplot1.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) subplot1.getRenderer();

    renderer1.setBaseLinesVisible(false);
    renderer1.setBaseShapesVisible(true);
    renderer1.setBaseShapesFilled(true);

    int[] num_group = new int[num_series];
    Paint color_mainGroup = mEMexperiment[0].getColorOfMainGroup();

    // use same color   for all series if EM together    
    //  System.out.println("dataset0. seriescount="+dataset[0].getSeriesCount()+" itemcount="+dataset[0].getItemCount(0));
    if (num_series == 1)
        for (int s = 0; s < dataset[0].getSeriesCount(); s++) {
            renderer1.setSeriesLinesVisible(s, false);
            renderer1.setSeriesShapesVisible(s, true);
            renderer1.setSeriesShapesFilled(s, true);
            renderer1.setSeriesShape(s, series_shapes[0]); // for the shape of the dots
            renderer1.setSeriesPaint(s, color_mainGroup);
        }

    //  System.out.println("num_series="+num_series);
    //   System.out.println("num_group="+num_group);
    //  System.out.println("segment_flag="+segment_flag);

    if (legend) {
        LegendItemCollection legends_old = subplot1.getFixedLegendItems();
        LegendItemCollection legends_new = new LegendItemCollection();
        for (int s = 0; s < num_series; s++) {
            legends_new.add(legends_old.get(s));
        }
        subplot1.setFixedLegendItems(legends_new);

    }
    //segment

    for (int s = 0; s < num_series; s++) {
        num_group[s] = mEMexperiment[s].getNumOfGroup();
    }

    // System.out.println("num_group[0]="+num_group[0]);

    if (num_group[0] > 0 && segment_flag && (mixSelected == CG_MIX)) {
        Paint[] color_groups = mEMexperiment[0].getColorOfGroups();

        for (int i = 0; i < num_group[0] - 1; i++) {
            //System.out.println("color "+ i +"=" + color_groups[i].toString());
            renderer1.setSeriesPaint(i, color_groups[i]);
        }
        //System.out.println("color main ="+ color_mainGroup.toString());
        renderer1.setSeriesPaint(nkSelected, color_mainGroup);
    } else
        renderer1.setBasePaint(color_mainGroup);

    // renderer1.setShape(series_shapes[0]);   

    // subplot1.setDataset(0, dataset[0]);
    //System.out.println("setting renderer for " +0);
    //   subplot1.setRenderer(0, renderer1);
    // System.out.println("SOCR_EM creatChart: pt0="+dataset.getXValue(0, 0)+ ","+dataset.getYValue(0, 0));

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) subplot1.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);
    //   rangeAxis.setUpperMargin(0);
    //  rangeAxis.setLowerMargin(0);

    NumberAxis domainAxis = (NumberAxis) subplot1.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(true);
    //  domainAxis.setUpperMargin(0);
    //  domainAxis.setLowerMargin(0);

    XYLineAndShapeRenderer[] renderer1a = new XYLineAndShapeRenderer[num_series];
    if (num_series > 1) {
        for (int s = 0; s < num_series; s++) {
            //   System.out.println("adding pt for series:"+s +": seriesCount "+ dataset[s].getSeriesCount()+"itemcount="+dataset[s].getItemCount(0));
            renderer1a[s] = new XYLineAndShapeRenderer();
            if (num_group[0] > 0 && segment_flag && (mixSelected == CG_MIX)) {
                Paint[] color_groups = mEMexperiment[0].getColorOfGroups();

                for (int i = 0; i < num_group[0] - 1; i++) {
                    //System.out.println("color "+ i +"=" + color_groups[i].toString());
                    renderer1a[s].setSeriesPaint(i, color_groups[i]);
                }
                //System.out.println("color main ="+ color_mainGroup.toString());
                renderer1a[s].setSeriesPaint(nkSelected, color_mainGroup);
            } else
                renderer1a[s].setBasePaint(color_mainGroup);
            renderer1a[s].setBaseLinesVisible(false);
            renderer1a[s].setBaseShapesVisible(true);
            renderer1a[s].setBaseShapesFilled(true);
            renderer1a[s].setBaseShape(series_shapes[s]); // different shape of dots for each pair of input    
            subplot1.setDataset(s, dataset[s]);
            // System.out.println("setting renderer for " +s);
            subplot1.setRenderer(s, renderer1a[s]);
        }

    }

    if (kernels != null) {
        /*  System.out.println("draw kernels");
          System.out.println("num_series="+num_series);
          System.out.println("nkSelected="+nkSelected);*/
        XYLineAndShapeRenderer[][] renderer2 = new XYLineAndShapeRenderer[num_series][nkSelected];
        for (int s = 0; s < num_series; s++) {

            Paint[] color_kernels = mEMexperiment[s].getColorOfKernels();
            // System.out.println("SOCR_EM creatChart adding kernels:" +num_kernels+ "ws[0]="+ws[0]);
            for (int i = 0; i < nkSelected; i++) {
                // System.out.println("drawing kernel for series: "+s +" kernel:" +i);
                //  System.out.println("SOCR_EM creatChart: kernel "+i+" pt0="+kernels[i].getXValue(0, 0)+","+kernels[i].getYValue(0, 0));
                renderer2[s][i] = new XYLineAndShapeRenderer();
                renderer2[s][i].setBaseStroke(series_strokes[s]);
                renderer2[s][i].setBaseLinesVisible(true);
                renderer2[s][i].setBaseShapesVisible(false);
                //  renderer2[s][i].setShapesFilled(false);
                renderer2[s][i].setBasePaint(color_kernels[i]);
                subplot1.setDataset(num_series - 1 + s * num_series + i + 1, kernels[s][i]);
                // System.out.println("setting renderer for " +(num_series-1+s*num_series+i+1));
                subplot1.setRenderer(num_series - 1 + s * num_series + i + 1, renderer2[s][i]);
                //subplot1.setRangeAxis(i+1, rangeAxis);
            } //i
        } //s
    }

    segment_flag = false;
    return chart;

}