本文整理了Java中org.jfree.chart.JFreeChart
类的一些代码示例,展示了JFreeChart
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFreeChart
类的具体详情如下:
包路径:org.jfree.chart.JFreeChart
类名称:JFreeChart
[英]A chart class implemented using the Java 2D APIs. The current version supports bar charts, line charts, pie charts and xy plots (including time series data).
JFreeChart coordinates several objects to achieve its aim of being able to draw a chart on a Java 2D graphics device: a list of Title objects (which often includes the chart's legend), a Plot and a org.jfree.data.general.Dataset (the plot in turn manages a domain axis and a range axis).
You should use a ChartPanel to display a chart in a GUI.
The ChartFactory class contains static methods for creating 'ready-made' charts.
[中]使用Java2D API实现的图表类。当前版本支持条形图、折线图、饼图和xy图(包括时间序列数据)。
JFreeChart协调多个对象以实现在Java 2D图形设备上绘制图表的目标:标题对象列表(通常包括图表的图例)、绘图和组织。jfree。数据全体的数据集(绘图依次管理域轴和范围轴)。
您应该使用图表面板在GUI中显示图表。
ChartFactory类包含用于创建“现成”图表的静态方法。
代码示例来源:origin: pentaho/pentaho-kettle
ChartFactory.createLineChart( chartTitle, // chart title
BaseMessages.getString( PKG, "StepPerformanceSnapShotDialog.TimeInSeconds.Label", Integer
true, // tooltips
false ); // urls
chart.setBackgroundPaint( Color.white );
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint( Color.white );
plot.setForegroundAlpha( 0.5f );
plot.setRangeGridlinesVisible( true );
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits( NumberAxis.createIntegerTickUnits() );
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setTickLabelsVisible( false );
renderer.setSeriesShape( 0, new Ellipse2D.Double( -3.0, -3.0, 6.0, 6.0 ) );
BufferedImage bufferedImage = chart.createBufferedImage( bounds.width, bounds.height );
ImageData imageData = ImageUtil.convertToSWT( bufferedImage );
代码示例来源:origin: stackoverflow.com
final JFreeChart result = ChartFactory.createTimeSeriesChart(
TITLE, "hh:mm:ss", "milliVolts", dataset, true, true, false);
final XYPlot plot = result.getXYPlot();
ValueAxis domain = plot.getDomainAxis();
domain.setAutoRange(true);
ValueAxis range = plot.getRangeAxis();
range.setRange(-MINMAX, MINMAX);
return result;
代码示例来源:origin: kiegroup/optaplanner
@Override
public void writeGraphFiles(BenchmarkReport benchmarkReport) {
Locale locale = benchmarkReport.getLocale();
NumberAxis xAxis = new NumberAxis("Time spent");
xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale));
NumberAxis yAxis = new NumberAxis("Score calculation speed per second");
yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
yAxis.setAutoRangeIncludesZero(false);
XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
plot.setOrientation(PlotOrientation.VERTICAL);
int seriesIndex = 0;
for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) {
plot.setDataset(seriesIndex, new XYSeriesCollection(series));
renderer.setSeriesStroke(0, new BasicStroke(2.0f));
plot.setRenderer(seriesIndex, renderer);
seriesIndex++;
JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " score calculation speed statistic",
JFreeChart.DEFAULT_TITLE_FONT, plot, true);
graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "ScoreCalculationSpeedStatistic");
代码示例来源:origin: jenkinsci/jenkins
/**
* Draws a chart into {@link JFreeChart}.
*/
public JFreeChart createChart() {
final JFreeChart chart = ChartFactory.createLineChart(null, // chart title
null, // unused
null, // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.white);
chart.getLegend().setItemFont(CHART_FONT);
final CategoryPlot plot = chart.getCategoryPlot();
configurePlot(plot);
configureRangeAxis((NumberAxis) plot.getRangeAxis());
crop(plot);
return chart;
}
代码示例来源:origin: jenkinsci/jenkins
final JFreeChart chart = ChartFactory.createLineChart(null, // chart title
);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlinePaint(null);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.black);
plot.setDomainAxis(domainAxis);
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
domainAxis.setCategoryMargin(0.0);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
代码示例来源:origin: jenkinsci/jenkins
private BufferedImage render(StaplerRequest req, ChartRenderingInfo info) {
String w = req.getParameter("width");
if(w==null) w=String.valueOf(defaultW);
String h = req.getParameter("height");
if(h==null) h=String.valueOf(defaultH);
Color graphBg = stringToColor(req.getParameter("graphBg"));
Color plotBg = stringToColor(req.getParameter("plotBg"));
if (graph==null) graph = createGraph();
graph.setBackgroundPaint(graphBg);
Plot p = graph.getPlot();
p.setBackgroundPaint(plotBg);
return graph.createBufferedImage(Integer.parseInt(w),Integer.parseInt(h),info);
}
代码示例来源:origin: jenkinsci/jenkins
final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart
);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlinePaint(null);
plot.setForegroundAlpha(0.8f);
plot.setDomainAxis(domainAxis);
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
domainAxis.setCategoryMargin(0.0);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
ChartUtil.adjustChebyshev(dataset, rangeAxis);
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
代码示例来源:origin: org.jenkins-ci.plugins/global-build-stats
private JFreeChart createChart(final BuildStatConfiguration config, List<AbstractBuildStatChartDimension> dimensions, String title) {
final JFreeChart chart = ChartFactory.createStackedAreaChart(title, null, "",
new DataSetBuilder<String, DateRange>().build(), PlotOrientation.VERTICAL, true, true, false);
chart.setBackgroundPaint(Color.white);
final LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
final CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setForegroundAlpha(0.85F);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.darkGray);
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
domainAxis.setCategoryMargin(0.0);
plot.setDomainAxis(domainAxis);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
代码示例来源:origin: org.sakaiproject.sitestats/sitestats-impl
private byte[] generateBoxAndWhiskerChart (BoxAndWhiskerCategoryDataset dataset, int width, int height)
{
JFreeChart chart = ChartFactory.createBoxAndWhiskerChart (null, null,
null, dataset, false);
// set background
chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ()));
// set chart border
chart.setPadding (new RectangleInsets (10, 5, 5, 5));
chart.setBorderVisible (true);
chart.setBorderPaint (parseColor ("#cccccc"));
// set anti alias
chart.setAntiAlias (true);
CategoryPlot plot = (CategoryPlot) chart.getPlot ();
plot.setDomainGridlinePaint (Color.white);
plot.setDomainGridlinesVisible (true);
plot.setRangeGridlinePaint (Color.white);
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis ();
rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ());
CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis ();
domainAxis.setLowerMargin (0.0);
domainAxis.setUpperMargin (0.0);
BufferedImage img = chart.createBufferedImage (width, height);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
try{
ImageIO.write(img, "png", out);
}catch(IOException e){
log.warn("Error occurred while generating SiteStats chart image data", e);
}
return out.toByteArray();
}
代码示例来源:origin: psi-probe/psi-probe
chart = ChartFactory.createXYAreaChart("", labelX, labelY, ds, PlotOrientation.VERTICAL,
showLegend, false, false);
((XYAreaRenderer) chart.getXYPlot().getRenderer()).setOutline(true);
chart = ChartFactory.createStackedXYAreaChart("", labelX, labelY, ds,
PlotOrientation.VERTICAL, showLegend, false, false);
chart.getXYPlot().setRenderer(renderer);
chart.setAntiAlias(true);
chart.setBackgroundPaint(new Color(backgroundColor));
for (int i = 0; i < seriesMaxCount; i++) {
if (seriesColor[i] >= 0) {
chart.getXYPlot().getRenderer().setSeriesPaint(i, new Color(seriesColor[i]));
chart.getXYPlot().getRenderer().setSeriesOutlinePaint(i,
new Color(seriesOutlineColor[i]));
chart.getXYPlot().setDomainGridlinePaint(new Color(gridColor));
chart.getXYPlot().setRangeGridlinePaint(new Color(gridColor));
chart.getXYPlot().setDomainAxis(0, new DateAxis());
chart.getXYPlot().setDomainAxis(1, new DateAxis());
chart.getXYPlot().setInsets(new RectangleInsets(-15, 0, 0, 10));
.write(ChartUtilities.encodeAsPNG(chart.createBufferedImage(width, height)));
代码示例来源:origin: com.atlassian.jira/jira-core
public ChartHelper generateChart()
{
boolean legend = false;
boolean tooltips = false;
boolean urls = false;
JFreeChart chart = ChartFactory.createStackedBarChart(null, null, yLabel, dataset, PlotOrientation.VERTICAL, legend, tooltips, urls);
setStackedBarChartDefaults(chart, i18nBean);
CategoryPlot plot = chart.getCategoryPlot();
NumberAxis axis = (NumberAxis) plot.getRangeAxis();
TickUnitSource units = NumberAxis.createIntegerTickUnits();
axis.setStandardTickUnits(units);
CategoryAxis catAxis = plot.getDomainAxis();
catAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
plot.getRenderer().setSeriesOutlinePaint(1, ChartDefaults.GREEN_DIFF);
plot.getRenderer().setSeriesPaint(1, ChartDefaults.GREEN_DIFF);
plot.getRenderer().setSeriesOutlinePaint(0, ChartDefaults.RED_DIFF);
plot.getRenderer().setSeriesPaint(0, ChartDefaults.RED_DIFF);
return new ChartHelper(chart);
}
代码示例来源:origin: de.tudarmstadt.ukp.dkpro.tc/de.tudarmstadt.ukp.dkpro.tc.weka-gpl
@Override
public void write(OutputStream aStream)
throws IOException
{
JFreeChart chart = ChartFactory.createXYLineChart(null, "Recall", "Precision", dataset,
PlotOrientation.VERTICAL, false, false, false);
chart.getXYPlot().setRenderer(new XYSplineRenderer());
chart.getXYPlot().getRangeAxis().setRange(0.0, 1.0);
chart.getXYPlot().getDomainAxis().setRange(0.0, 1.0);
ChartUtil.writeChartAsSVG(aStream, chart, 400, 400);
}
}
代码示例来源:origin: stackoverflow.com
title, "X", "Y", createSampleData(),
PlotOrientation.VERTICAL, true, true, false);
XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
xyPlot.setDomainCrosshairVisible(true);
xyPlot.setRangeCrosshairVisible(true);
XYItemRenderer renderer = xyPlot.getRenderer();
renderer.setSeriesPaint(0, Color.blue);
NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
domain.setRange(0.00, 1.00);
domain.setTickUnit(new NumberTickUnit(0.1));
domain.setVerticalTickLabels(true);
NumberAxis range = (NumberAxis) xyPlot.getRangeAxis();
range.setRange(0.0, 1.0);
代码示例来源:origin: org.hudsonci.plugins/analysis-core
NumberAxis numberAxis = new NumberAxis("count");
numberAxis.setAutoRange(true);
numberAxis.setAutoRangeIncludesZero(false);
CategoryAxis domainAxis = new CategoryAxis();
domainAxis.setCategoryMargin(0.0);
CategoryPlot plot = new CategoryPlot(dataSet, domainAxis, numberAxis, new LineAndShapeRenderer(true, false));
plot.setOrientation(PlotOrientation.VERTICAL);
JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, hasLegend);
if (hasLegend) {
chart.getLegend().setItemFont(LEGEND_FONT);
chart.setBackgroundPaint(Color.white);
代码示例来源:origin: mikaelhg/openblocks
public ChartPanel getOutputPanel() {
//we return a copy of the chart because we only want to show the
//legend in the larger view of the graph
//not the small runtime graph block view
JFreeChart newChart = new JFreeChart(chart.getPlot());
newChart.getLegend().setPosition(RectangleEdge.TOP);
newChart.getLegend().setPadding(5, 5, 5, 5);
newChart.setBackgroundPaint(background);
output = new ChartPanel(newChart);
return output;
}
代码示例来源:origin: com.atlassian.confluence.extra.chart/chart-plugin
public static void setDefaults(JFreeChart chart)
{
chart.setBackgroundPaint(ChartDefaults.transparent);
chart.setBorderVisible(false);
chart.getPlot().setNoDataMessage("No Data Available");
setupPlot(chart.getPlot());
ChartUtil.setupTextTitle(chart.getTitle());
ChartUtil.setupLegendTitle(chart.getLegend());
}
代码示例来源:origin: com.atlassian.jira.plugins/jira-fisheye-plugin
public static ChartHelper generateStackedBarChart(CategoryDataset dataset, String chartTitle, String yLabel, String xLabel, List domainMarkers)
{
boolean legend = false;
boolean tooltips = false;
boolean urls = false;
JFreeChart chart = ChartFactory.createStackedBarChart(chartTitle, yLabel, xLabel, dataset, PlotOrientation.VERTICAL, legend, tooltips, urls);
chart.setBackgroundPaint(Color.WHITE);
chart.setBorderVisible(false);
CategoryPlot plot = chart.getCategoryPlot();
NumberAxis axis = (NumberAxis) plot.getRangeAxis();
TickUnitSource units = NumberAxis.createIntegerTickUnits();
axis.setStandardTickUnits(units);
plot.getRenderer().setSeriesOutlinePaint(1, COLOR_YELLOW_OUTLINE);
plot.getRenderer().setSeriesPaint(1, COLOR_YELLOW_PAINT);
plot.getRenderer().setSeriesOutlinePaint(0, COLOR_CYAN_OUTLINE);
plot.getRenderer().setSeriesPaint(0, COLOR_CYAN_PAINT);
return new ChartHelper(chart);
}
代码示例来源:origin: kiegroup/optaplanner
maximumEndDate = Math.max(maximumEndDate, endDate);
NumberAxis domainAxis = new NumberAxis("Job");
domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
domainAxis.setRange(-0.5, schedule.getAllocationList().size() - 0.5);
domainAxis.setInverted(true);
NumberAxis rangeAxis = new NumberAxis("Day (start to end date)");
rangeAxis.setRange(-0.5, maximumEndDate + 0.5);
XYPlot plot = new XYPlot(seriesCollection, domainAxis, rangeAxis, renderer);
plot.setOrientation(PlotOrientation.HORIZONTAL);
return new JFreeChart("Project Job Scheduling", JFreeChart.DEFAULT_TITLE_FONT,
plot, true);
代码示例来源:origin: jenkinsci/build-failure-analyzer-plugin
@Override
protected JFreeChart createGraph() {
CategoryDataset dataset = createDataset();
JFreeChart chart = ChartFactory.createBarChart(graphTitle, "", "Number of failures", dataset,
PlotOrientation.HORIZONTAL, false, false, false);
NumberAxis domainAxis = new NumberAxis();
domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
CategoryPlot plot = (CategoryPlot)chart.getPlot();
plot.setRangeAxis(domainAxis);
BarRenderer renderer = (BarRenderer)plot.getRenderer();
renderer.setMaximumBarWidth(MAX_BAR_WIDTH);
return chart;
}
代码示例来源:origin: us.ihmc/ihmc-avatar-interfaces
private JFreeChart createChart(String title, XYDataset magDataset, String freqUnits, String magnitudeUnits)
{
XYItemRenderer renderer1 = new StandardXYItemRenderer();
NumberAxis rangeAxis1 = new NumberAxis("Magnitude " + magnitudeUnits);
XYPlot subplot1 = new XYPlot(magDataset, new LogarithmicAxis("Frequency " + freqUnits), rangeAxis1, renderer1);
subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
renderer1.setSeriesVisibleInLegend(0, false);
return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, subplot1, true);
}
}
内容来源于网络,如有侵权,请联系作者删除!