use of org.jfree.chart.axis.ValueAxis in project pentaho-platform by pentaho.
the class JFreeChartEngine method createBarChart.
private static JFreeChart createBarChart(final CategoryDatasetChartDefinition chartDefinition) {
// TODO Make the following accessible from the chartDefinition
String categoryAxisLabel = null;
String valueAxisLabel = null;
boolean tooltips = true;
boolean urls = true;
// -----------------------------------------------------------
String title = chartDefinition.getTitle();
boolean legend = chartDefinition.isLegendIncluded();
PlotOrientation orientation = chartDefinition.getOrientation();
CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
BarRenderer renderer = null;
// Determine the type of renderer to use
if (chartDefinition.isStacked() || chartDefinition.isThreeD()) {
if (chartDefinition.isStacked() && chartDefinition.isThreeD()) {
renderer = new StackedBarRenderer3D();
} else if (chartDefinition.isStacked()) {
renderer = new StackedBarRenderer();
} else {
renderer = new BarRenderer3D();
}
} else {
renderer = new BarRenderer();
}
if (orientation == PlotOrientation.HORIZONTAL) {
ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);
renderer.setPositiveItemLabelPosition(position1);
ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT);
renderer.setNegativeItemLabelPosition(position2);
} else if (orientation == PlotOrientation.VERTICAL) {
ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
renderer.setPositiveItemLabelPosition(position1);
ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
renderer.setNegativeItemLabelPosition(position2);
}
if (tooltips) {
renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
}
if (urls) {
renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
}
if (chartDefinition.getMaxBarWidth() != null) {
renderer.setMaximumBarWidth(chartDefinition.getMaxBarWidth().doubleValue());
}
CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer);
JFreeChartEngine.updatePlot(plot, chartDefinition);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
use of org.jfree.chart.axis.ValueAxis in project pentaho-platform by pentaho.
the class JFreeChartEngine method updatePlot.
private static void updatePlot(final Plot plot, final ChartDefinition chartDefinition) {
plot.setBackgroundPaint(chartDefinition.getPlotBackgroundPaint());
plot.setBackgroundImage(chartDefinition.getPlotBackgroundImage());
plot.setNoDataMessage(chartDefinition.getNoDataMessage());
// create a custom palette if it was defined
if (chartDefinition.getPaintSequence() != null) {
DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(chartDefinition.getPaintSequence(), DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
plot.setDrawingSupplier(drawingSupplier);
}
// TODO define outline stroke
plot.setOutlineStroke(null);
if (plot instanceof CategoryPlot) {
CategoryPlot categoryPlot = (CategoryPlot) plot;
CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
categoryPlot.setOrientation(categoryDatasetChartDefintion.getOrientation());
CategoryAxis domainAxis = categoryPlot.getDomainAxis();
if (domainAxis != null) {
domainAxis.setLabel(categoryDatasetChartDefintion.getDomainTitle());
domainAxis.setLabelFont(categoryDatasetChartDefintion.getDomainTitleFont());
if (categoryDatasetChartDefintion.getDomainTickFont() != null) {
domainAxis.setTickLabelFont(categoryDatasetChartDefintion.getDomainTickFont());
}
domainAxis.setCategoryLabelPositions(categoryDatasetChartDefintion.getCategoryLabelPositions());
}
NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
if (numberAxis != null) {
numberAxis.setLabel(categoryDatasetChartDefintion.getRangeTitle());
numberAxis.setLabelFont(categoryDatasetChartDefintion.getRangeTitleFont());
if (categoryDatasetChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
numberAxis.setLowerBound(categoryDatasetChartDefintion.getRangeMinimum());
}
if (categoryDatasetChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
numberAxis.setUpperBound(categoryDatasetChartDefintion.getRangeMaximum());
}
if (categoryDatasetChartDefintion.getRangeTickFormat() != null) {
numberAxis.setNumberFormatOverride(categoryDatasetChartDefintion.getRangeTickFormat());
}
if (categoryDatasetChartDefintion.getRangeTickFont() != null) {
numberAxis.setTickLabelFont(categoryDatasetChartDefintion.getRangeTickFont());
}
if (categoryDatasetChartDefintion.getRangeTickUnits() != null) {
numberAxis.setTickUnit(new NumberTickUnit(categoryDatasetChartDefintion.getRangeTickUnits()));
}
}
}
if (plot instanceof PiePlot) {
PiePlot pie = (PiePlot) plot;
PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition;
pie.setInteriorGap(pieDefinition.getInteriorGap());
pie.setStartAngle(pieDefinition.getStartAngle());
pie.setLabelFont(pieDefinition.getLabelFont());
if (pieDefinition.getLabelPaint() != null) {
pie.setLabelPaint(pieDefinition.getLabelPaint());
}
pie.setLabelBackgroundPaint(pieDefinition.getLabelBackgroundPaint());
if (pieDefinition.isLegendIncluded()) {
// $NON-NLS-1$
StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}");
pie.setLegendLabelGenerator(labelGen);
}
if (pieDefinition.getExplodedSlices() != null) {
for (Iterator iter = pieDefinition.getExplodedSlices().iterator(); iter.hasNext(); ) {
pie.setExplodePercent((Comparable) iter.next(), .30);
}
}
pie.setLabelGap(pieDefinition.getLabelGap());
if (!pieDefinition.isDisplayLabels()) {
pie.setLabelGenerator(null);
} else {
if (pieDefinition.isLegendIncluded()) {
// $NON-NLS-1$
StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})");
pie.setLabelGenerator(labelGen);
} else {
// $NON-NLS-1$
StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0} = {1} ({2})");
pie.setLabelGenerator(labelGen);
}
}
}
if (plot instanceof MultiplePiePlot) {
MultiplePiePlot pies = (MultiplePiePlot) plot;
CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
pies.setDataset(categoryDatasetChartDefintion);
}
if (plot instanceof MeterPlot) {
MeterPlot meter = (MeterPlot) plot;
DialWidgetDefinition widget = (DialWidgetDefinition) chartDefinition;
List intervals = widget.getIntervals();
Iterator intervalIterator = intervals.iterator();
while (intervalIterator.hasNext()) {
MeterInterval interval = (MeterInterval) intervalIterator.next();
meter.addInterval(interval);
}
meter.setNeedlePaint(widget.getNeedlePaint());
meter.setDialShape(widget.getDialShape());
meter.setDialBackgroundPaint(widget.getPlotBackgroundPaint());
meter.setRange(new Range(widget.getMinimum(), widget.getMaximum()));
}
if (plot instanceof XYPlot) {
XYPlot xyPlot = (XYPlot) plot;
if (chartDefinition instanceof XYSeriesCollectionChartDefinition) {
XYSeriesCollectionChartDefinition xySeriesCollectionChartDefintion = (XYSeriesCollectionChartDefinition) chartDefinition;
xyPlot.setOrientation(xySeriesCollectionChartDefintion.getOrientation());
ValueAxis domainAxis = xyPlot.getDomainAxis();
if (domainAxis != null) {
domainAxis.setLabel(xySeriesCollectionChartDefintion.getDomainTitle());
domainAxis.setLabelFont(xySeriesCollectionChartDefintion.getDomainTitleFont());
domainAxis.setVerticalTickLabels(xySeriesCollectionChartDefintion.isDomainVerticalTickLabels());
if (xySeriesCollectionChartDefintion.getDomainTickFormat() != null) {
((NumberAxis) domainAxis).setNumberFormatOverride(xySeriesCollectionChartDefintion.getDomainTickFormat());
}
if (xySeriesCollectionChartDefintion.getDomainTickFont() != null) {
domainAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getDomainTickFont());
}
if (xySeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
domainAxis.setLowerBound(xySeriesCollectionChartDefintion.getDomainMinimum());
}
if (xySeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
domainAxis.setUpperBound(xySeriesCollectionChartDefintion.getDomainMaximum());
}
}
ValueAxis rangeAxis = xyPlot.getRangeAxis();
if (rangeAxis != null) {
rangeAxis.setLabel(xySeriesCollectionChartDefintion.getRangeTitle());
rangeAxis.setLabelFont(xySeriesCollectionChartDefintion.getRangeTitleFont());
if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
}
if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
}
if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
}
if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
}
if (xySeriesCollectionChartDefintion.getRangeTickFormat() != null) {
((NumberAxis) rangeAxis).setNumberFormatOverride(xySeriesCollectionChartDefintion.getRangeTickFormat());
}
if (xySeriesCollectionChartDefintion.getRangeTickFont() != null) {
rangeAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getRangeTickFont());
}
}
} else if (chartDefinition instanceof TimeSeriesCollectionChartDefinition) {
TimeSeriesCollectionChartDefinition timeSeriesCollectionChartDefintion = (TimeSeriesCollectionChartDefinition) chartDefinition;
xyPlot.setOrientation(timeSeriesCollectionChartDefintion.getOrientation());
ValueAxis domainAxis = xyPlot.getDomainAxis();
if (domainAxis != null) {
domainAxis.setLabel(timeSeriesCollectionChartDefintion.getDomainTitle());
domainAxis.setLabelFont(timeSeriesCollectionChartDefintion.getDomainTitleFont());
domainAxis.setVerticalTickLabels(timeSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
if (domainAxis instanceof DateAxis) {
DateAxis da = (DateAxis) domainAxis;
if (timeSeriesCollectionChartDefintion.getDateMinimum() != null) {
da.setMinimumDate(timeSeriesCollectionChartDefintion.getDateMinimum());
}
if (timeSeriesCollectionChartDefintion.getDateMaximum() != null) {
da.setMaximumDate(timeSeriesCollectionChartDefintion.getDateMaximum());
}
}
}
ValueAxis rangeAxis = xyPlot.getRangeAxis();
if (rangeAxis != null) {
rangeAxis.setLabel(timeSeriesCollectionChartDefintion.getRangeTitle());
rangeAxis.setLabelFont(timeSeriesCollectionChartDefintion.getRangeTitleFont());
if (timeSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
rangeAxis.setLowerBound(timeSeriesCollectionChartDefintion.getRangeMinimum());
}
if (timeSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
rangeAxis.setUpperBound(timeSeriesCollectionChartDefintion.getRangeMaximum());
}
}
} else if (chartDefinition instanceof XYZSeriesCollectionChartDefinition) {
XYZSeriesCollectionChartDefinition xyzSeriesCollectionChartDefintion = (XYZSeriesCollectionChartDefinition) chartDefinition;
xyPlot.setOrientation(xyzSeriesCollectionChartDefintion.getOrientation());
ValueAxis domainAxis = xyPlot.getDomainAxis();
if (domainAxis != null) {
domainAxis.setLabel(xyzSeriesCollectionChartDefintion.getDomainTitle());
domainAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getDomainTitleFont());
domainAxis.setVerticalTickLabels(xyzSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
if (xyzSeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
domainAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getDomainMinimum());
}
if (xyzSeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
domainAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getDomainMaximum());
}
if (xyzSeriesCollectionChartDefintion.getDomainTickFormat() != null) {
((NumberAxis) domainAxis).setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getDomainTickFormat());
}
if (xyzSeriesCollectionChartDefintion.getDomainTickFont() != null) {
domainAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getDomainTickFont());
}
}
ValueAxis rangeAxis = xyPlot.getRangeAxis();
if (rangeAxis != null) {
rangeAxis.setLabel(xyzSeriesCollectionChartDefintion.getRangeTitle());
rangeAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getRangeTitleFont());
rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
if (xyzSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
}
if (xyzSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
rangeAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getRangeMaximum());
}
if (xyzSeriesCollectionChartDefintion.getRangeTickFormat() != null) {
((NumberAxis) rangeAxis).setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getRangeTickFormat());
}
if (xyzSeriesCollectionChartDefintion.getRangeTickFont() != null) {
rangeAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getRangeTickFont());
}
}
}
}
}
use of org.jfree.chart.axis.ValueAxis in project pentaho-platform by pentaho.
the class JFreeChartEngine method createTimeSeriesCollectionChart.
private static JFreeChart createTimeSeriesCollectionChart(final TimeSeriesCollectionChartDefinition chartDefinition) {
JFreeChart chart = null;
// TODO Make the following accessible from the chartDefinition
String domainAxisLabel = null;
String rangeAxisLabel = null;
boolean tooltips = true;
boolean urls = true;
// -----------------------------------------------------------
String title = chartDefinition.getTitle();
boolean legend = chartDefinition.isLegendIncluded();
DateAxis domainAxis = new DateAxis(domainAxisLabel, TimeZone.getDefault());
ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel);
XYItemRenderer renderer = null;
switch(chartDefinition.getChartType()) {
case LINE_CHART_TYPE:
renderer = chartDefinition.isThreeD() ? new XYLine3DRenderer() : new XYLineAndShapeRenderer(true, false);
((XYLineAndShapeRenderer) renderer).setShapesVisible(chartDefinition.isMarkersVisible());
((XYLineAndShapeRenderer) renderer).setBaseShapesFilled(chartDefinition.isMarkersVisible());
break;
case AREA_CHART_TYPE:
renderer = new XYAreaRenderer();
break;
case STEP_CHART_TYPE:
renderer = new XYStepRenderer();
break;
case STEP_AREA_CHART_TYPE:
renderer = new XYStepAreaRenderer();
break;
case DIFFERENCE_CHART_TYPE:
renderer = new XYDifferenceRenderer();
break;
case DOT_CHART_TYPE:
renderer = new XYDotRenderer();
((XYDotRenderer) renderer).setDotHeight(chartDefinition.getDotHeight());
((XYDotRenderer) renderer).setDotWidth(chartDefinition.getDotWidth());
break;
default:
// should log an error if invalid chart type passed in - at least return null for no renderer
return null;
}
if (tooltips) {
XYToolTipGenerator generator = new StandardXYToolTipGenerator(chartDefinition.getTooltipContent(), new SimpleDateFormat(chartDefinition.getTooltipXFormat()), new DecimalFormat(chartDefinition.getTooltipYFormat()));
renderer.setToolTipGenerator(generator);
}
if (urls) {
renderer.setURLGenerator(new StandardXYURLGenerator());
}
renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth()));
XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer);
JFreeChartEngine.updatePlot(plot, chartDefinition);
chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
use of org.jfree.chart.axis.ValueAxis in project pentaho-platform by pentaho.
the class JFreeChartEngine method createLineChart.
private static JFreeChart createLineChart(final CategoryDatasetChartDefinition chartDefinition) {
// TODO Make the following accessible from the chartDefinition
String categoryAxisLabel = null;
String valueAxisLabel = null;
boolean tooltips = true;
boolean urls = true;
// -----------------------------------------------------------
String title = chartDefinition.getTitle();
boolean legend = chartDefinition.isLegendIncluded();
CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
LineAndShapeRenderer renderer = chartDefinition.isThreeD() ? new LineRenderer3D() : new LineAndShapeRenderer(true, false);
if (tooltips) {
renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
}
if (urls) {
renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
}
renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth()));
renderer.setShapesVisible(chartDefinition.isMarkersVisible());
renderer.setBaseShapesFilled(chartDefinition.isMarkersVisible());
CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer);
JFreeChartEngine.updatePlot(plot, chartDefinition);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
use of org.jfree.chart.axis.ValueAxis in project Course_Generator by patrovite.
the class JPanelAnalysisSpeed method Refresh.
/**
* Update the Time/Distance chart
*/
public void Refresh(TrackData track, CgSettings settings) {
if (track == null)
return;
if (track.data.isEmpty())
return;
this.track = track;
this.settings = settings;
// -- Calculate the speed regression
/*
* y = ax + b a = the slope of the trend line. b = the intercept of the
* trend line.
*/
double xAvg = 0;
double yAvg = 0;
double v = 0;
CgData r;
for (int x = 0; x < track.data.size(); x++) {
r = track.data.get(x);
xAvg += x;
yAvg += (r.getSpeed(settings.Unit) / (100 / r.getDiff())) / (100 / r.getCoeff());
}
xAvg = xAvg / track.data.size();
yAvg = yAvg / track.data.size();
double v1 = 0;
double v2 = 0;
for (int x = 0; x < track.data.size(); x++) {
r = track.data.get(x);
v = (r.getSpeed(settings.Unit) / (100 / r.getDiff())) / (100 / r.getCoeff());
v1 += (x - xAvg) * (v - yAvg);
v2 += Math.pow(x - xAvg, 2);
}
double a = v1 / v2;
double b = yAvg - a * xAvg;
// -- Clear all series
if (datasetSpeedReg.getSeriesCount() > 0)
datasetSpeedReg.removeAllSeries();
if (datasetSpeed.getSeriesCount() > 0)
datasetSpeed.removeAllSeries();
XYPlot plot = chart.getXYPlot();
plot.clearDomainMarkers();
// -- Populate the serie
XYSeries serie1 = new XYSeries("Speed regression/Distance");
XYSeries serie2 = new XYSeries("Speed/Distance");
startSpeed = 0.0;
endSpeed = 0.0;
double maxspeed = 0.0;
double cmpt = 0.0;
for (CgData d : track.data) {
double x = d.getTotal(settings.Unit) / 1000;
double y = d.getSpeed(settings.Unit);
if (x < 0.001)
x = 0;
if (y > maxspeed)
maxspeed = y;
if (cmpt == 0)
startSpeed = (b / (100 / d.getDiff())) / (100 / d.getCoeff());
if (cmpt == track.data.size() - 1)
endSpeed = ((a * x + b) / (100 / d.getDiff())) / (100 / d.getCoeff());
cmpt++;
serie1.add(x, y / (100.0 / d.getDiff()) / (100.0 / d.getCoeff()));
serie2.add(x, a * cmpt + b);
}
// -- If there is no speed the exit (not already calculated)
if (maxspeed == 0.0)
return;
datasetSpeedReg.addSeries(serie2);
datasetSpeed.addSeries(serie1);
ValueAxis axisY = plot.getRangeAxis(0);
axisY.setRange(0.0, Math.ceil(maxspeed / 5.0) * 5.0);
axisY = plot.getRangeAxis(1);
axisY.setRange(0.0, Math.ceil(maxspeed / 5.0) * 5.0);
chart = CreateChart(datasetSpeedReg, datasetSpeed);
RefreshInfo(0);
}
Aggregations