List of usage examples for org.jfree.chart.axis AxisLocation BOTTOM_OR_RIGHT
AxisLocation BOTTOM_OR_RIGHT
To view the source code for org.jfree.chart.axis AxisLocation BOTTOM_OR_RIGHT.
Click Source Link
From source file:v800_trainer.XYGraphik.java
public JPanel StartGraphik(JCicloTronic JTronicHandle) { int num = 0;//from w w w . j a v a 2s .com int num2 = 0, num0, num02; //fr Streckendifferenz int selected; int single; int i; int j; int Stunden; int Minuten; int Sekunden; int Tagadder = 0; int Linecount = 0; Second xTime[]; double xWerte[]; double xWerte2[];//fr Streckendifferenz double y1Werte[]; double y2Werte[]; double y3Werte[]; double y4Werte[]; double y5Werte[]; double y6Werte[]; double y7Werte[]; double y8Werte[]; double y8bWerte[]; double y9Werte[]; double y10Werte[]; JFreeChart chart; Rectangle2D.Double Legendenpunkt = new Rectangle2D.Double(); selected = JTronicHandle.Auswahl_Graphik.getSelectedIndex(); if (selected == 0) { single = 1; } else { single = 0; } //Defaultchart erstellen if (JTronicHandle.Graphik_Radio_Strecke.isSelected()) { XYSeries dataset = new XYSeries(""); dataset.add(1, 1); XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); chart = ChartFactory.createXYLineChart("Multiple Axis Demo 1", "Strecke", "", dataset1, PlotOrientation.HORIZONTAL, true, true, false); } else { TimeSeries dataset = new TimeSeries(""); dataset.add(new Second(1, 1, 1, 1, 1, 1900), 1); TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 1", "Zeit", "", dataset1, true, true, false); } ; //Tooltips fr Zeitachse einstellen // XYToolTipGenerator ToolTip = new StandardXYToolTipGenerator("{0}: ({1}, {2})", // (DateFormat) new SimpleDateFormat("kk:mm.ss"), // NumberFormat.getInstance()); // chart.setAntiAlias(true); chart.setNotify(false); if (single == 0) { chart.setTitle(JTronicHandle.Statistikhandle.TourData[JTronicHandle.Auswahl_Graphik .getSelectedIndex()].DataProperty.getProperty("Titel", "")); chart.addSubtitle(new TextTitle(JTronicHandle.Auswahl_Graphik.getItemAt(selected).toString())); } else { chart.setTitle("Mehrfache Daten"); } chart.setBackgroundPaint(Color.white); JTronicHandle.applyChartTheme(chart); XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); 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); plot.setRangeCrosshairLockedOnData(false); plot.setDomainCrosshairLockedOnData(false); int Anzahl_Kurven = Integer.parseInt(JTronicHandle.Properties.getProperty("AnzahlKurven", "5")) + 1; if (Anzahl_Kurven > JTronicHandle.Auswahl_Graphik.getItemCount()) { Anzahl_Kurven = JTronicHandle.Auswahl_Graphik.getItemCount(); } try { for (j = 0; j < (Anzahl_Kurven - 2) * single + 1; j++) { if (single == 1) { selected = j + 1; } num = JTronicHandle.Statistikhandle.TourData[selected].Datenpunkte; num2 = JTronicHandle.Statistikhandle.TourData[selected].ZahlStreckenPunkte; num0 = JTronicHandle.Statistikhandle.TourData[1].ZahlStreckenPunkte; num02 = JTronicHandle.Statistikhandle.TourData[1].Datenpunkte; xTime = new Second[num]; xWerte = new double[num]; y1Werte = new double[num]; y2Werte = new double[num]; y3Werte = new double[num]; y4Werte = new double[num]; y5Werte = new double[num]; y6Werte = new double[num]; y7Werte = new double[num]; y8Werte = new double[num]; y8bWerte = new double[num]; xWerte2 = new double[num2]; y9Werte = new double[num2]; y10Werte = new double[num]; for (i = 0; i < num; i++) { xWerte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Strecke_gesZeit[i]; y1Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Geschw_gesZeit[i]; y2Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Hoehe_gesZeit[i]; y3Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Hf_gesZeit[i]; y4Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Temperatur_gesZeit[i]; y5Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Steigp_gesZeit[i]; y6Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Steigm_gesZeit[i]; y7Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].av_Geschw_gesZeit[i]; y8Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Cadence_gesZeit[i]; y8bWerte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Schritt_lnge[i]; } if (JTronicHandle.Graphik_check_Abstand.isSelected() && single == 1 && j != 0) { int p = 0; if (JTronicHandle.Graphik_Radio_Strecke.isSelected()) { for (i = 0; i < num2; i++) { xWerte2[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Streckenskala[i]; if (i < num0) { y9Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].ZeitberStrecke[i] - JTronicHandle.Statistikhandle.TourData[1].ZeitberStrecke[i]; } else { y9Werte[i] = y9Werte[i - 1]; } } } else { for (i = 0; i < num; i++) { p = 0; while (p < num02 - 1 && (JTronicHandle.Statistikhandle.TourData[selected].gesZeit[i] >= JTronicHandle.Statistikhandle.TourData[1].gesZeit[p])) { p++; } ; if (i < num02) { y10Werte[i] = (double) (JTronicHandle.Statistikhandle.TourData[selected].Strecke_gesZeit[i] - JTronicHandle.Statistikhandle.TourData[1].Strecke_gesZeit[p]) * 100.0; } else { y10Werte[i] = y10Werte[i - 1]; } } } } //Zeitbasis laden for (i = 0; i < num; i++) { Tagadder = 0; Stunden = (int) (JTronicHandle.Statistikhandle.TourData[selected].gesZeit[i] / 3600); Minuten = (int) ((JTronicHandle.Statistikhandle.TourData[selected].gesZeit[i] - Stunden * 3600) / 60); Sekunden = (int) (JTronicHandle.Statistikhandle.TourData[selected].gesZeit[i] - Stunden * 3600 - Minuten * 60); if (single == 0) { Minuten = Minuten + JTronicHandle.Statistikhandle.TourData[selected].StartMinuten; if (Minuten >= 60) { Minuten -= 60; Stunden++; } ; Stunden = Stunden + JTronicHandle.Statistikhandle.TourData[selected].StartStunden; } ; while (Stunden >= 24) { Stunden -= 24; Tagadder += 1; } ; try { if (single == 0) { xTime[i] = new Second(Sekunden, Minuten, Stunden, JTronicHandle.Statistikhandle.TourData[selected].Tag + Tagadder, JTronicHandle.Statistikhandle.TourData[selected].Monat, JTronicHandle.Statistikhandle.TourData[selected].Jahr); } else { xTime[i] = new Second(Sekunden, Minuten, Stunden, 1 + Tagadder, 1, 1900); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "StartGraphik\n" + e + "Zeile " + i + " Zeitfehler " + Stunden + " " + Minuten + " " + Sekunden, "Achtung!", JOptionPane.ERROR_MESSAGE); } } if (JTronicHandle.Graphik_Radio_Strecke.isSelected()) { //Streckenachse if (JTronicHandle.Graphik_check_Geschwindigkeit.isSelected()) { XYSeries dataset = new XYSeries( "Geschwindigkeit [km/h] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y1Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Hhe.isSelected()) { XYSeries dataset = new XYSeries( "Hhe [m] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y2Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); NumberAxis axis2 = new NumberAxis("Hhe [m]"); axis2.setLabelFont(plot.getRangeAxis().getLabelFont()); axis2.setTickLabelFont(plot.getRangeAxis().getTickLabelFont()); axis2.setAutoRangeIncludesZero(true); axis2.setLabelPaint(Color.BLACK); axis2.setTickLabelPaint(Color.BLACK); axis2.setAxisLinePaint(Color.BLACK); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 1); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } ; if (JTronicHandle.Graphik_check_HF.isSelected()) { XYSeries dataset = new XYSeries( "Herzfrequenz [b/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y3Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Temp.isSelected()) { XYSeries dataset = new XYSeries( "Temperatur [C] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y4Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Steigung_p.isSelected()) { XYSeries dataset = new XYSeries( "Steigung [%] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y5Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Steigung_m.isSelected()) { XYSeries dataset = new XYSeries( "Steigung [m/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y6Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_av_Geschw.isSelected()) { XYSeries dataset = new XYSeries( "av Geschw. [km/h] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y7Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Cadence.isSelected()) { XYSeries dataset = new XYSeries( "Cadence [n/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y8Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Schrittlnge.isSelected()) { XYSeries dataset = new XYSeries( "Schrittlnge [cm] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y8bWerte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Abstand.isSelected() && single == 1 && j != 0) { XYSeries dataset = new XYSeries( "Zeitabstand [s] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr + " - " + JTronicHandle.Statistikhandle.TourData[1].Tag + "." + JTronicHandle.Statistikhandle.TourData[1].Monat + "." + JTronicHandle.Statistikhandle.TourData[1].Jahr); for (i = 0; i < num2; i++) { dataset.add(xWerte2[i], y9Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); NumberAxis axis3 = new NumberAxis("Abstand"); axis3.setLabelFont(plot.getRangeAxis().getLabelFont()); axis3.setTickLabelFont(plot.getRangeAxis().getTickLabelFont()); axis3.setAutoRangeIncludesZero(true); axis3.setLabelPaint(Color.BLACK); axis3.setTickLabelPaint(Color.BLACK); plot.setRangeAxis(2, axis3); plot.setRangeAxisLocation(2, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 2); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } } else { //Zeitachse if (JTronicHandle.Graphik_check_Geschwindigkeit.isSelected()) { TimeSeries dataset = new TimeSeries( "Geschwindigkeit [km/h] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y1Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); ValueAxis axis = plot.getRangeAxis(); axis.setLabelPaint(Color.BLACK); axis.setTickLabelPaint(Color.BLACK); plot.setRangeAxis(0, axis); plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Hhe.isSelected()) { TimeSeries dataset = new TimeSeries( "Hoehe [m] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y2Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); NumberAxis axis2 = (NumberAxis) plot.getRangeAxis().clone(); axis2.setLabel("Hhe [m]"); axis2.setAutoRangeIncludesZero(true); axis2.setLabelPaint(Color.BLACK); axis2.setTickLabelPaint(Color.BLACK); axis2.setAxisLinePaint(Color.BLACK); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 1); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_HF.isSelected()) { TimeSeries dataset = new TimeSeries( "Herzfrequenz [b/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y3Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Temp.isSelected()) { TimeSeries dataset = new TimeSeries( "Temperatur [C] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y4Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Steigung_p.isSelected()) { TimeSeries dataset = new TimeSeries("Steigung [%] "); for (i = 0; i < num; i++) { dataset.add(xTime[i], y5Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Steigung_m.isSelected()) { TimeSeries dataset = new TimeSeries( "Steigung [m/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y6Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_av_Geschw.isSelected()) { TimeSeries dataset = new TimeSeries( "av Geschw. [km/h] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y7Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Cadence.isSelected()) { TimeSeries dataset = new TimeSeries( "Cadence [n/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y8Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Schrittlnge.isSelected()) { TimeSeries dataset = new TimeSeries( "Schrittlnge [cm] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y8bWerte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Abstand.isSelected() && single == 1 && j != 0) { TimeSeries dataset = new TimeSeries( "Streckenabstand [m] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr + " - " + JTronicHandle.Statistikhandle.TourData[1].Tag + "." + JTronicHandle.Statistikhandle.TourData[1].Monat + "." + JTronicHandle.Statistikhandle.TourData[1].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y10Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); ValueAxis axis3 = (ValueAxis) plot.getRangeAxis().clone(); axis3.setLabel("Abstand"); axis3.setLabelPaint(Color.BLACK); axis3.setTickLabelPaint(Color.BLACK); plot.setRangeAxis(2, axis3); plot.setRangeAxisLocation(2, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 2); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } } } chart.setNotify(true); ChartPanel Panel = new ChartPanel(chart); return Panel; } catch (Exception e) { JOptionPane.showMessageDialog(null, "StartGraphik\nSchluss_Fehler: " + e, "Achtung!", JOptionPane.ERROR_MESSAGE); } return new ChartPanel(chart); }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getLastLogin(Session s) throws CloneNotSupportedException { Integer numCurrentLogins = ((Long) s .createQuery("select count(*) from UserModel " + "where currentLogin is not null and currentLogin >= :date") .setDate("date", getStartDate()).uniqueResult()).intValue(); List currentStats = s// w w w .j a v a 2s .c o m .createSQLQuery("SELECT DATE(currentLogin) as date, count( * ) as lastLogins " + "FROM users where currentLogin is not null and currentLogin >= :date " + "GROUP BY DATE( currentLogin )") .addScalar("date", Hibernate.DATE).addScalar("lastLogins", Hibernate.INTEGER) .setDate("date", getStartDate()).list(); TimeSeriesCollection theData = new TimeSeriesCollection(); TimeSeriesCollection theData2 = new TimeSeriesCollection(); TimeSeries current = new TimeSeries("Num Latest Sign-ins", Day.class); theData.addSeries(current); TimeSeries current2 = new TimeSeries("Signed-in Users Since", Day.class); theData2.addSeries(current2); for (Object ds : currentStats) { Date date = (Date) ((Object[]) ds)[0]; Day day = new Day(date); Integer integer = (Integer) ((Object[]) ds)[1]; current.add(day, integer); numCurrentLogins -= integer.intValue(); current2.add(day, numCurrentLogins); } JFreeChart chart = ChartFactory.createTimeSeriesChart("Sign-in Recency", "Day", "Sign-ins", theData, true, true, true); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis axis2 = new NumberAxis("Users"); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, theData2); plot.mapDatasetToRangeAxis(1, 1); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(0); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f)); renderer = (XYLineAndShapeRenderer) renderer.clone(); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f)); plot.setRenderer(1, renderer); return chart; }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java
/** * Add the series// w ww .ja v a2 s. c o m * * * @param series The data * @param lineState describes how to draw the line * @param paramIdx which parameter * @param renderer renderer * @param rangeVisible do we show range axis * @param addAxis include the axis * * @return the newly created range axis */ protected Axis addSeries(TimeSeries series, LineState lineState, int paramIdx, XYItemRenderer renderer, boolean rangeVisible, boolean addAxis) { if (series instanceof MyTimeSeries) { ((MyTimeSeries) series).finish(); } if (addAxis && (lineState.getRange() != null)) { addRange(lineState.getRange().getMin(), lineState.getRange().getMax(), "Fixed range from: " + lineState.getName()); } if (numberFormat == null) { numberFormat = new DecimalFormat() { public StringBuffer format(double number, StringBuffer result, FieldPosition fieldPosition) { String s = control.getDisplayConventions().format(number); result.append(s); return result; } }; } String name = lineState.getName(); Unit unit = lineState.unit; TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.setDomainIsPointsInTime(true); dataset.addSeries(series); String axisLabel = lineState.getAxisLabel(); if (axisLabel == null) { axisLabel = name + ((unit != null) ? " [" + unit + "]" : ""); } NumberAxis rangeAxis; if (lineState.getUseLogarithmicRange() && false) { rangeAxis = new FixedWidthLogarithmicAxis(axisLabel); } else { rangeAxis = new FixedWidthNumberAxis(axisLabel); ((NumberAxis) rangeAxis).setAutoRangeIncludesZero(lineState.getRangeIncludesZero()); } //For now lets use the default number formatting for the range // rangeAxis.setNumberFormatOverride(numberFormat); rangeAxis.setVisible(rangeVisible); ucar.unidata.util.Range r = lineState.getRange(); if (r != null) { rangeAxis.setRange(new org.jfree.data.Range(r.getMin(), r.getMax())); } if (renderer == null) { renderer = getRenderer(lineState, addAxis); } Paint c = lineState.getColor(paramIdx); rangeAxis.setLabelPaint(Color.black); renderer.setSeriesPaint(0, c); renderer.setSeriesStroke(0, lineState.getStroke()); renderer.setSeriesVisibleInLegend(0, lineState.getVisibleInLegend()); if (!lineState.getAxisVisible()) { rangeAxis.setVisible(false); } else { rangeAxis.setVisible(addAxis); } ChartHolder chartHolder = getChartHolder(lineState); AxisLocation side = null; if (rangeAxis.isVisible()) { if (lineState.getSide() == LineState.SIDE_UNDEFINED) { if (chartHolder.lastSide == AxisLocation.TOP_OR_LEFT) { side = AxisLocation.BOTTOM_OR_RIGHT; } else { side = AxisLocation.TOP_OR_LEFT; } } else if (lineState.getSide() == LineState.SIDE_LEFT) { side = AxisLocation.TOP_OR_LEFT; } else { side = AxisLocation.BOTTOM_OR_RIGHT; } chartHolder.lastSide = side; } synchronized (MUTEX) { chartHolder.add(dataset, rangeAxis, renderer, side); } return rangeAxis; }
From source file:sim.app.sugarscape.util.ResultsGrapher.java
JFreeChart createChart1(XYSeries[] series) { JFreeChart chart3 = ChartFactory.createXYLineChart("Results", x_axis_fieldname, y_axis_fieldname, null, //new XYSeriesCollection(series[2]), PlotOrientation.VERTICAL, true, true, false); //System.out.println("Series count = " +series[0].getItemCount()); XYPlot plot = chart3.getXYPlot();//from w w w .j a v a 2s . c o m ValueAxis yAxis = plot.getRangeAxis(); //xAxis.setFixedDimension(100); //yAxis.setFixedDimension(1.0); //yAxis.setRange(0,1); ValueAxis xAxis = plot.getDomainAxis(); //xAxis.setFixedDimension(50); StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, Color.black); renderer.setStroke(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); renderer.setItemLabelFont(new Font("Serif", Font.PLAIN, 20)); renderer.setItemLabelsVisible(true); renderer.setSeriesItemLabelsVisible(1, true); renderer.setBaseShapesVisible(true); //XYLabelGenerator generator = new StandardXYLabelGenerator(); //"{2}", new DecimalFormat("0.00") ); //renderer.setLabelGenerator(generator); //NumberAxis axis2 = new NumberAxis("Average Agent Vision"); //renderer.setItemLabelsVisible(true); //axis2.setAutoRangeIncludesZero(false); //axis2.setRange(0,12); //plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); //XYSeriesCollection vision = new XYSeriesCollection(lorenz_agent_vision); //plot.setDataset(1, vision); //String first_letter = x_param_fieldname.substring(0,1)+"="; XYSeriesCollection xys = new XYSeriesCollection(); for (int a = 0; a < series.length; a++) { xys.addSeries(series[a]); //xys. //xys.getSeriesName(4); System.out.println(xys.getSeries(a).getDescription()); } plot.setDataset(0, xys); return chart3; }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * Method createChart.//from w ww. j av a2s. c om * * @param strategyData * StrategyData * @param title * String * @return JFreeChart */ private JFreeChart createChart(StrategyData strategyData, String title, Tradingday tradingday) { DateAxis dateAxis = new DateAxis("Date"); dateAxis.setVerticalTickLabels(true); dateAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm")); dateAxis.setTickMarkPosition(DateTickMarkPosition.START); NumberAxis priceAxis = new NumberAxis("Price"); priceAxis.setAutoRange(true); priceAxis.setAutoRangeIncludesZero(false); XYPlot pricePlot = new XYPlot(strategyData.getCandleDataset(), dateAxis, priceAxis, strategyData.getCandleDataset().getRenderer()); pricePlot.setOrientation(PlotOrientation.VERTICAL); pricePlot.setDomainPannable(true); pricePlot.setRangePannable(true); pricePlot.setDomainCrosshairVisible(true); pricePlot.setDomainCrosshairLockedOnData(true); pricePlot.setRangeCrosshairVisible(true); pricePlot.setRangeCrosshairLockedOnData(true); pricePlot.setRangeGridlinePaint(new Color(204, 204, 204)); pricePlot.setDomainGridlinePaint(new Color(204, 204, 204)); pricePlot.setBackgroundPaint(Color.white); /* * Calculate the number of 15min segments in this trading day. i.e. * 6.5hrs/15min = 26 and there are a total of 96 = one day */ int segments15min = (int) (tradingday.getClose().getTime() - tradingday.getOpen().getTime()) / (1000 * 60 * 15); SegmentedTimeline segmentedTimeline = new SegmentedTimeline(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE, segments15min, (96 - segments15min)); Date startDate = tradingday.getOpen(); Date endDate = tradingday.getClose(); if (!strategyData.getCandleDataset().getSeries(0).isEmpty()) { startDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0).getDataItem(0)).getPeriod() .getStart(); startDate = TradingCalendar.getSpecificTime(tradingday.getOpen(), startDate); endDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0) .getDataItem(strategyData.getCandleDataset().getSeries(0).getItemCount() - 1)).getPeriod() .getStart(); endDate = TradingCalendar.getSpecificTime(tradingday.getClose(), endDate); } segmentedTimeline.setStartTime(startDate.getTime()); segmentedTimeline.addExceptions(getNonTradingPeriods(startDate, endDate, tradingday.getOpen(), tradingday.getClose(), segmentedTimeline)); dateAxis.setTimeline(segmentedTimeline); // Build Combined Plot CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(dateAxis); mainPlot.add(pricePlot, 4); int axixIndex = 0; int datasetIndex = 0; /* * Change the List of indicators so that the candle dataset is the first * one in the list. The main chart must be plotted first. */ List<IndicatorDataset> indicators = new ArrayList<IndicatorDataset>(0); for (IndicatorDataset item : strategyData.getIndicators()) { if (IndicatorSeries.CandleSeries.equals(item.getType(0))) { indicators.add(item); } } for (IndicatorDataset item : strategyData.getIndicators()) { if (!IndicatorSeries.CandleSeries.equals(item.getType(0))) { indicators.add(item); } } for (int i = 0; i < indicators.size(); i++) { IndicatorDataset indicator = indicators.get(i); if (indicator.getDisplaySeries(0)) { if (indicator.getSubChart(0)) { String axisName = "Price"; if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) { axisName = ((CandleSeries) indicator.getSeries(0)).getSymbol(); } else { org.trade.dictionary.valuetype.IndicatorSeries code = org.trade.dictionary.valuetype.IndicatorSeries .newInstance(indicator.getType(0)); axisName = code.getDisplayName(); } NumberAxis subPlotAxis = new NumberAxis(axisName); subPlotAxis.setAutoRange(true); subPlotAxis.setAutoRangeIncludesZero(false); XYPlot subPlot = new XYPlot((XYDataset) indicator, dateAxis, subPlotAxis, indicator.getRenderer()); subPlot.setOrientation(PlotOrientation.VERTICAL); subPlot.setDomainPannable(true); subPlot.setRangePannable(true); subPlot.setDomainCrosshairVisible(true); subPlot.setDomainCrosshairLockedOnData(true); subPlot.setRangeCrosshairVisible(true); subPlot.setRangeCrosshairLockedOnData(true); subPlot.setRangeGridlinePaint(new Color(204, 204, 204)); subPlot.setDomainGridlinePaint(new Color(204, 204, 204)); subPlot.setBackgroundPaint(Color.white); XYItemRenderer renderer = subPlot.getRendererForDataset((XYDataset) indicator); for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator) .getSeriesCount(); seriesIndex++) { renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex)); } mainPlot.add(subPlot, 1); } else { datasetIndex++; pricePlot.setDataset(datasetIndex, (XYDataset) indicator); if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) { // add secondary axis axixIndex++; final NumberAxis axis2 = new NumberAxis( ((CandleSeries) indicator.getSeries(0)).getSymbol()); axis2.setAutoRange(true); axis2.setAutoRangeIncludesZero(false); pricePlot.setRangeAxis(datasetIndex, axis2); pricePlot.setRangeAxisLocation(i + 1, AxisLocation.BOTTOM_OR_RIGHT); pricePlot.mapDatasetToRangeAxis(datasetIndex, axixIndex); pricePlot.setRenderer(datasetIndex, new StandardXYItemRenderer()); } else { pricePlot.setRenderer(datasetIndex, indicator.getRenderer()); } XYItemRenderer renderer = pricePlot.getRendererForDataset((XYDataset) indicator); for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator) .getSeriesCount(); seriesIndex++) { renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex)); } } } } JFreeChart jfreechart = new JFreeChart(title, null, mainPlot, true); jfreechart.setAntiAlias(false); return jfreechart; }
From source file:com.romraider.logger.ecu.ui.tab.DynoChartPanel.java
private void configurePlot(JFreeChart chart) { plot = chart.getXYPlot();//ww w . j a v a2 s . co m plot.setOutlinePaint(DARK_GREY); plot.setBackgroundPaint(BLACK); // X axis settings plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.getDomainAxis().setLabelPaint(WHITE); plot.getDomainAxis().setTickLabelPaint(LIGHT_GREY); plot.setDomainGridlinePaint(DARK_GREY); // Y1 axis (left) settings hpAxis.setLabel(labelY1); hpAxis.setLabelPaint(BLUE); hpAxis.setTickLabelPaint(LIGHT_GREY); hpAxis.setAutoRangeIncludesZero(false); hpAxis.setAutoRange(true); plot.setRangeAxis(0, hpAxis); plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); plot.mapDatasetToRangeAxis(0, 0); plot.mapDatasetToRangeAxis(2, 0); // Y2 axis (right) settings tqAxis.setLabel(labelY2); tqAxis.setLabelPaint(YELLOW); tqAxis.setTickLabelPaint(LIGHT_GREY); tqAxis.setAutoRangeIncludesZero(false); tqAxis.setAutoRange(true); plot.setRangeAxis(1, tqAxis); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.mapDatasetToRangeAxis(1, 1); plot.mapDatasetToRangeAxis(3, 1); plot.setRangeGridlinePaint(DARK_GREY); refStat.setPaint(WHITE); refStat.setTextAnchor(TextAnchor.TOP_LEFT); refStat.setFont(new Font("SansSerif", Font.BOLD, 12)); }
From source file:com.romraider.logger.ecu.ui.tab.dyno.DynoChartPanel.java
private void configurePlot(JFreeChart chart) { plot = chart.getXYPlot();/*from w w w . j av a2 s. co m*/ plot.setOutlinePaint(DARK_GREY); plot.setBackgroundPaint(BLACK); // X axis settings plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.getDomainAxis().setLabelPaint(WHITE); plot.getDomainAxis().setTickLabelPaint(LIGHT_GREY); plot.setDomainGridlinePaint(DARK_GREY); // Y1 axis (left) settings hpAxis.setLabel(labelY1); hpAxis.setLabelPaint(BLUE); hpAxis.setTickLabelPaint(LIGHT_GREY); hpAxis.setAutoRangeIncludesZero(false); hpAxis.setAutoRange(true); plot.setRangeAxis(0, hpAxis); plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); plot.mapDatasetToRangeAxis(0, 0); plot.mapDatasetToRangeAxis(2, 0); // Y2 axis (right) settings tqAxis.setLabel(labelY2); tqAxis.setLabelPaint(YELLOW); tqAxis.setTickLabelPaint(LIGHT_GREY); tqAxis.setAutoRangeIncludesZero(false); tqAxis.setAutoRange(true); plot.setRangeAxis(1, tqAxis); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.mapDatasetToRangeAxis(1, 1); plot.mapDatasetToRangeAxis(3, 1); plot.setRangeGridlinePaint(DARK_GREY); refStat.setPaint(WHITE); refStat.setTextAnchor(TextAnchor.TOP_LEFT); refStat.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 12)); }
From source file:org.sakaiproject.gradebookng.tool.panels.SettingsGradingSchemaPanel.java
/** * Build the data for the chart/* ww w .j a v a2s . c o m*/ * * @return */ private JFreeChart getChartData() { // just need the list final List<CourseGrade> courseGrades = this.courseGradeMap.values().stream().collect(Collectors.toList()); // get current grading schema (from model so that it reflects current state) final List<GbGradingSchemaEntry> gradingSchemaEntries = this.model.getObject().getGradingSchemaEntries(); final DefaultCategoryDataset data = new DefaultCategoryDataset(); final Map<String, Integer> counts = new LinkedHashMap<>(); // must retain order so graph can be printed correctly // add all schema entries (these will be sorted according to {@link LetterGradeComparator}) gradingSchemaEntries.forEach(e -> { counts.put(e.getGrade(), 0); }); // now add the count of each course grade for those schema entries this.total = 0; for (final CourseGrade g : courseGrades) { // course grade may not be released so we have to skip it if (StringUtils.isBlank(g.getMappedGrade())) { continue; } counts.put(g.getMappedGrade(), counts.get(g.getMappedGrade()) + 1); this.total++; } // build the data final ListIterator<String> iter = new ArrayList<>(counts.keySet()).listIterator(0); while (iter.hasNext()) { final String c = iter.next(); data.addValue(counts.get(c), "count", c); } final JFreeChart chart = ChartFactory.createBarChart(null, // the chart title getString("settingspage.gradingschema.chart.xaxis"), // the label for the category (x) axis getString("label.statistics.chart.yaxis"), // the label for the value (y) axis data, // the dataset for the chart PlotOrientation.HORIZONTAL, // the plot orientation false, // show legend true, // show tooltips false); // show urls chart.getCategoryPlot().setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); chart.setBorderVisible(false); chart.setAntiAlias(false); final CategoryPlot plot = chart.getCategoryPlot(); final BarRenderer br = (BarRenderer) plot.getRenderer(); br.setItemMargin(0); br.setMinimumBarLength(0.05); br.setMaximumBarWidth(0.1); br.setSeriesPaint(0, new Color(51, 122, 183)); br.setBarPainter(new StandardBarPainter()); br.setShadowPaint(new Color(220, 220, 220)); BarRenderer.setDefaultShadowsVisible(true); br.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(getString("label.statistics.chart.tooltip"), NumberFormat.getInstance())); plot.setRenderer(br); // show only integers in the count axis plot.getRangeAxis().setStandardTickUnits(new NumberTickUnitSource(true)); // make x-axis wide enough so we don't get ... suffix plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(2.0f); plot.setBackgroundPaint(Color.white); chart.setTitle(getString("settingspage.gradingschema.chart.heading")); return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.StackedBarGroup.java
/** * Inherited by IChart./* w w w .j ava 2 s . c o m*/ * * @param chartTitle the chart title * @param dataset the dataset * * @return the j free chart */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1"); logger.debug("Get plot orientaton"); PlotOrientation plotOrientation = PlotOrientation.VERTICAL; if (horizontalView) { plotOrientation = PlotOrientation.HORIZONTAL; } JFreeChart chart = ChartFactory.createStackedBarChart(name, // chart title categoryLabel, // domain axis label valueLabel, // range axis label dataset, // data plotOrientation, // the plot orientation legend, // legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(color); plot.setRangeGridlinePaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap("G1"); int numElForGroup = 0; for (int idx = 0; idx < numGroups.intValue(); idx++) { for (int j = 0; j < numSerieForGroup.intValue(); j++) { try { String tmpSubCat = (String) subCategoryNames.get(j + idx * numSerieForGroup.intValue()); map.mapKeyToGroup(tmpSubCat, "G" + (idx + 1)); } catch (Exception e) { logger.error("out of range error in inserting in stacked bar group: continue anayway", e); } } } renderer.setSeriesToGroupMap(map); renderer.setItemMargin(0.0); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); if (percentageValue) renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("#,##.#%"))); else renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); if (maxBarWidth != null) { renderer.setMaximumBarWidth(maxBarWidth.doubleValue()); } boolean document_composition = false; if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION)) document_composition = true; /* MyCategoryUrlGenerator mycatUrl=new MyCategoryUrlGenerator(rootUrl); mycatUrl.setDocument_composition(document_composition); mycatUrl.setCategoryUrlLabel(categoryUrlName); mycatUrl.setSerieUrlLabel(serieUrlname); renderer.setItemURLGenerator(mycatUrl); */ TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(color); NumberFormat nf = NumberFormat.getNumberInstance(locale); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor()); rangeAxis.setNumberFormatOverride(nf); if (rangeIntegerValues == true) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } if (rangeAxisLocation != null) { if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); } } int seriesN = dataset.getRowCount(); int numSerieColored = 0; if (orderColorVector != null && orderColorVector.size() > 0) { logger.debug("color serie by SERIES_ORDER_COLORS template specification"); for (int i = 0; i < seriesN; i++) { if (orderColorVector.get(i) != null) { Color color = orderColorVector.get(i); renderer.setSeriesPaint(i, color); } } } else if (colorMap != null) { while (numSerieColored < seriesN) { for (int i = 1; i <= colorMap.size(); i++) { Color color = (Color) colorMap.get("SER" + i); Color gradient = new Color(Integer.decode("#FFFFFF").intValue()); if (gradientMap != null) gradient = (Color) gradientMap.get("SER" + i); if (color != null) { Paint p = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, gradient); //renderer.setSeriesPaint(numSerieColored, color); renderer.setSeriesPaint(numSerieColored, p); } numSerieColored++; } } } renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); MyStandardCategoryItemLabelGenerator generator = null; if (additionalLabels) { generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance()); double orient = (-Math.PI / 2.0); if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) { orient = 0.0; } renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); //vertical labels renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); //horizontal labels /* renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition( ItemLabelAnchor.CENTER, TextAnchor.CENTER)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition( ItemLabelAnchor.CENTER, TextAnchor.CENTER)); */ } SubCategoryAxis domainAxis = new SubCategoryAxis(categoryLabel + " / " + subCategoryLabel); String subCatLabel = ""; for (int j = 1; j <= numGroups.intValue(); j++) { if (subCatLabelsMap != null) subCatLabel = (String) subCatLabelsMap.get("CAT" + j); else subCatLabel = subCategoryLabel; domainAxis.addSubCategory(subCatLabel); domainAxis .setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setLabelPaint(styleYaxesLabels.getColor()); domainAxis.setTickLabelFont( new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setTickLabelPaint(styleYaxesLabels.getColor()); } plot.setDomainAxis(domainAxis); plot.setRenderer(renderer); /* domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions( Math.PI / 6.0)); */ if (legend == true) drawLegend(chart); logger.debug("OUT"); return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.StackedBar.java
/** * Inherited by IChart./*w ww . j av a2 s .c o m*/ * * @param chartTitle the chart title * @param dataset the dataset * * @return the j free chart */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1"); logger.debug("Taken Dataset"); logger.debug("Get plot orientaton"); PlotOrientation plotOrientation = PlotOrientation.VERTICAL; if (horizontalView) { plotOrientation = PlotOrientation.HORIZONTAL; } logger.debug("Call Chart Creation"); JFreeChart chart = ChartFactory.createStackedBarChart(name, // chart title categoryLabel, // domain axis label valueLabel, // range axis label dataset, // data plotOrientation, // the plot orientation false, // legend true, // tooltips false // urls ); logger.debug("Chart Created"); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(color); plot.setRangeGridlinePaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); logger.debug("set renderer"); StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); if (percentageValue) renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("#,##.#%"))); else if (makePercentage) renderer.setRenderAsPercentages(true); /* else renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); */ renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); if (maxBarWidth != null) { renderer.setMaximumBarWidth(maxBarWidth.doubleValue()); } boolean document_composition = false; if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION)) document_composition = true; logger.debug("Calling Url Generation"); MyCategoryUrlGenerator mycatUrl = null; if (rootUrl != null) { logger.debug("Set MycatUrl"); mycatUrl = new MyCategoryUrlGenerator(rootUrl); mycatUrl.setDocument_composition(document_composition); mycatUrl.setCategoryUrlLabel(categoryUrlName); mycatUrl.setSerieUrlLabel(serieUrlname); } if (mycatUrl != null) renderer.setItemURLGenerator(mycatUrl); logger.debug("Text Title"); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } logger.debug("Style Labels"); Color colorSubInvisibleTitle = Color.decode("#FFFFFF"); StyleLabel styleSubSubTitle = new StyleLabel("Arial", 12, colorSubInvisibleTitle); TextTitle subsubTitle = setStyleTitle("", styleSubSubTitle); chart.addSubtitle(subsubTitle); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(color); logger.debug("Axis creation"); // set the range axis to display integers only... NumberFormat nf = NumberFormat.getNumberInstance(locale); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); if (makePercentage) rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); else rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (rangeIntegerValues == true) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor()); rangeAxis.setNumberFormatOverride(nf); if (rangeAxisLocation != null) { if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); } } renderer.setDrawBarOutline(false); logger.debug("Set series color"); int seriesN = dataset.getRowCount(); if (orderColorVector != null && orderColorVector.size() > 0) { logger.debug("color serie by SERIES_ORDER_COLORS template specification"); for (int i = 0; i < seriesN; i++) { if (orderColorVector.get(i) != null) { Color color = orderColorVector.get(i); renderer.setSeriesPaint(i, color); } } } else if (colorMap != null) { for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getRowKey(i); // if serie has been rinominated I must search with the new name! String nameToSearchWith = (seriesLabelsMap != null && seriesLabelsMap.containsKey(serieName)) ? seriesLabelsMap.get(serieName).toString() : serieName; Color color = (Color) colorMap.get(nameToSearchWith); if (color != null) { renderer.setSeriesPaint(i, color); renderer.setSeriesItemLabelFont(i, new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); } } } logger.debug("If cumulative set series paint " + cumulative); if (cumulative) { int row = dataset.getRowIndex("CUMULATIVE"); if (row != -1) { if (color != null) renderer.setSeriesPaint(row, color); else renderer.setSeriesPaint(row, Color.WHITE); } } MyStandardCategoryItemLabelGenerator generator = null; logger.debug("Are there addition labels " + additionalLabels); logger.debug("Are there value labels " + showValueLabels); if (showValueLabels) { renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); if (valueLabelsPosition.equalsIgnoreCase("inside")) { renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); } else { renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); } } else if (additionalLabels) { generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance()); logger.debug("generator set"); double orient = (-Math.PI / 2.0); logger.debug("add labels style"); if (styleValueLabels.getOrientation() != null && styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) { orient = 0.0; } renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); logger.debug("add labels style set"); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); //vertical labels renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER, TextAnchor.CENTER, orient)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER, TextAnchor.CENTER, orient)); logger.debug("end of add labels "); } logger.debug("domain axis"); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0)); domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setLabelPaint(styleYaxesLabels.getColor()); domainAxis .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setTickLabelPaint(styleYaxesLabels.getColor()); //opacizzazione colori if (!cumulative) plot.setForegroundAlpha(0.6f); if (legend == true) drawLegend(chart); logger.debug("OUT"); return chart; }