本文整理汇总了Java中org.jfree.chart.ChartUtilities.writeChartAsPNG方法的典型用法代码示例。如果您正苦于以下问题:Java ChartUtilities.writeChartAsPNG方法的具体用法?Java ChartUtilities.writeChartAsPNG怎么用?Java ChartUtilities.writeChartAsPNG使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jfree.chart.ChartUtilities
的用法示例。
在下文中一共展示了ChartUtilities.writeChartAsPNG方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String resultFile = req.getServletContext().getRealPath(
"/WEB-INF/glasanje-rezultati.txt");
String definitionFile = req.getServletContext().getRealPath(
"/WEB-INF/glasanje-definicija.txt");
List<Band> results = ServerUtilty
.getResults(definitionFile, resultFile);
JFreeChart chart = ServerUtilty.getChart(results);
ChartUtilities.writeChartAsPNG(resp.getOutputStream(), chart, 700, 400);
resp.getOutputStream().flush();
}
示例2: generatePieChart
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
* Controller that handles the chart generation for a question statistics
* @param surveyDefinitionId
* @param pageOrder
* @param questionOrder
* @param recordCount
* @param response
*/
@Secured({"ROLE_ADMIN","ROLE_SURVEY_ADMIN"})
@RequestMapping(value="/chart/{surveyDefinitionId}/{questionId}")
public void generatePieChart(@PathVariable("surveyDefinitionId") Long surveyDefinitionId,
@PathVariable("questionId") Long questionId,
HttpServletResponse response) {
try {
response.setContentType("image/png");
long recordCount = surveyService.surveyStatistic_get(surveyDefinitionId).getSubmittedCount();
PieDataset pieDataSet= createDataset(questionId,recordCount);
JFreeChart chart = createChart(pieDataSet, "");
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 340 ,200);
response.getOutputStream().close();
} catch (Exception e) {
log.error(e.getMessage(),e);
throw (new RuntimeException(e));
}
}
示例3: write
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
* @param out
* @return extension png or jpg for usage as file name extension.
*/
public String write(final OutputStream out)
{
final JFreeChart chart = getJFreeChart();
final int width = getWidth();
final int height = getHeight();
String extension = null;
try {
if (getImageType() == JFreeChartImageType.PNG) {
extension = "png";
ChartUtilities.writeChartAsPNG(out, chart, width, height);
} else {
extension = "jpg";
ChartUtilities.writeChartAsJPEG(out, chart, width, height);
}
} catch (final IOException ex) {
log.error("Exception encountered " + ex, ex);
}
return extension;
}
示例4: execute
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
public String execute() throws Exception{
response.setContentType("image/png");
OutputStream out = response.getOutputStream();
Convention c = (Convention)sessionData.get("conference");
// Create a simple Bar chart
//DefaultValueDataset dataset = new org.jfree.data.general.DefaultValueDataset();
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
if (c.conCap > 0) {
dataset.setValue(c.conCap,"Value","Event Cap");
}
dataset.setValue(c.numSubscribed,"Value","Subscribed");
dataset.setValue(c.numRegistered,"Value","Registered");
dataset.setValue(c.numBadged,"Value","Badged");
dataset.setValue(c.numCheckedin,"Value","Checkedin");
JFreeChart chart = ChartFactory.createBarChart(null,
null,null,dataset,PlotOrientation.HORIZONTAL,false,false,false);
ChartUtilities.writeChartAsPNG(out, chart, 750, 125);
return null;
}
示例5: doGet
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
List<PollOption> results = null;
try {
Long pollId = (Long) req.getSession().getAttribute("pollID");
results = DAOProvider.getDao().getPollOptions(pollId);
} catch (Exception ex) {
results = new ArrayList<>();
}
JFreeChart chart = DBUtility.getChart(results);
ChartUtilities.writeChartAsPNG(resp.getOutputStream(), chart, 700, 400);
}
示例6: createChart
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
* Creates a chart for recent time to fix.
*
*/
public void createChart(final SortedMap time, final String valueKey, final Color lineColor, final OutputStream out) throws IOException {
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
addTimeToDataSet(dataset, time, valueKey);
// create the chart object
// This generates a stacked bar - more suitable
final JFreeChart chart = ChartFactory.createLineChart(null,
"Recent builds", "Time", dataset,
PlotOrientation.VERTICAL,
true, false, false);
chart.setBackgroundPaint(Color.white);
// change the auto tick unit selection to integer units only
final CategoryPlot plot = chart.getCategoryPlot();
final NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
rangeAxis.setStandardTickUnits(StatisticsUtils.createWordedTimeTickUnits());
// rotate X dates
final CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
// set bar colors
final LineAndShapeRenderer line = (LineAndShapeRenderer)plot.getRenderer();
line.setSeriesPaint(0, lineColor);
line.setStroke(StatisticsUtils.DEFAULT_LINE_STROKE);
// write to reposnce
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
ChartUtilities.writeChartAsPNG(out, chart, StatisticsUtils.IMG_WIDTH, StatisticsUtils.IMG_HEIGHT, info);
}
示例7: handleRequest
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.GET)
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
String type = request.getParameter("type");
CategoryDataset dataset = createDataset(type);
JFreeChart chart = createChart(dataset, request);
int imageHeight = Math.max(IMAGE_MIN_HEIGHT, 15 * dataset.getColumnCount());
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, imageHeight);
return null;
}
示例8: doGet
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
JFreeChart chart = getChart();
ChartUtilities.writeChartAsPNG(resp.getOutputStream(), chart, 700, 400);
}
示例9: createChart
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
public void createChart(final SortedMap stats, final OutputStream out) throws IOException {
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (final Iterator iter = stats.entrySet().iterator(); iter.hasNext();) {
final Map.Entry entry = (Map.Entry)iter.next();
final Integer buildNumber = (Integer)entry.getKey();
final Integer violations = (Integer)entry.getValue();
dataset.addValue(violations, categoryDescription, buildNumber);
}
// create the chart object
// This generates a stacked bar - more suitable
final JFreeChart chart = ChartFactory.createLineChart(null,
"Recent builds", valueAxisLabel, dataset,
PlotOrientation.VERTICAL,
true, false, false);
chart.setBackgroundPaint(Color.white);
// change the auto tick unit selection to integer units only
final CategoryPlot plot = chart.getCategoryPlot();
final NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// rotate X dates
final CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
// set bar colors
final LineAndShapeRenderer line = (LineAndShapeRenderer)plot.getRenderer();
line.setSeriesPaint(0, Color.RED);
line.setStroke(StatisticsUtils.DEFAULT_LINE_STROKE);
// write to reposnce
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
ChartUtilities.writeChartAsPNG(out, chart, StatisticsUtils.IMG_WIDTH, StatisticsUtils.IMG_HEIGHT, info);
}
示例10: createTestsResultsChartHelper
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
*
*/
private static void createTestsResultsChartHelper(final String categoryLabel, final DefaultCategoryDataset dataset, final OutputStream out, final CategoryLabelPositions categoryLabelPosition) throws IOException {
final JFreeChart chart = ChartFactory.createStackedAreaChart(null,
categoryLabel, "Tests", dataset,
PlotOrientation.VERTICAL,
true, false, false);
chart.setBackgroundPaint(Color.white);
// change the auto tick unit selection to integer units only
final CategoryPlot plot = chart.getCategoryPlot();
final LogarithmicAxis logarithmicAxis = new LogarithmicAxis("Tests");
logarithmicAxis.setStrictValuesFlag(false);
logarithmicAxis.setAutoRangeIncludesZero(true);
logarithmicAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
plot.setRangeAxis(logarithmicAxis);
// final NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
// rotate X dates
final CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(categoryLabelPosition);
// set area colors
final StackedAreaRenderer area = (StackedAreaRenderer) plot.getRenderer();
area.setSeriesPaint(0, Color.RED); // first area
area.setSeriesPaint(1, Color.PINK); // second area
area.setSeriesPaint(2, Color.GREEN); // thirs area
//plot.setRenderer(area);
// write to reposnce
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
ChartUtilities.writeChartAsPNG(out, chart, IMG_WIDTH, IMG_HEIGHT, info);
}
示例11: createHourlyBreakageDistributionChart
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
public static void createHourlyBreakageDistributionChart(final SortedMap stats, final String categoryLabel, final OutputStream out) throws IOException {
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (final Iterator iter = stats.entrySet().iterator(); iter.hasNext();) {
final Map.Entry entry = (Map.Entry) iter.next();
final Integer hour = (Integer) entry.getKey();
final BuildStatistics bst = (BuildStatistics) entry.getValue();
dataset.addValue(new Integer(bst.getFailedBuilds()), "Failed builds", hour);
}
// create the chart object
// This generates a stacked bar - more suitable
final JFreeChart chart = ChartFactory.createStackedBarChart(null,
categoryLabel, "Builds", dataset,
PlotOrientation.VERTICAL,
true, false, false);
chart.setBackgroundPaint(Color.white);
// change the auto tick unit selection to integer units only
final CategoryPlot plot = chart.getCategoryPlot();
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// set bar colors
final BarRenderer bar = (BarRenderer) plot.getRenderer();
bar.setItemMargin(0); // reduce the width between the bars.
bar.setSeriesPaint(0, Color.RED); // first bar
// write to reposnce
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
ChartUtilities.writeChartAsPNG(out, chart, IMG_WIDTH, IMG_HEIGHT, info);
}
示例12: createRecentBuildTimesChart
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
public static void createRecentBuildTimesChart(final SortedMap stats, final String categoryLabel, final OutputStream out) throws IOException {
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (final Iterator iter = stats.entrySet().iterator(); iter.hasNext();) {
final Map.Entry entry = (Map.Entry) iter.next();
final Integer buildNumber = (Integer) entry.getKey();
final Integer timeInSeconds = (Integer) entry.getValue();
dataset.addValue(timeInSeconds, "Build time", buildNumber);
}
// create the chart object
// This generates a stacked bar - more suitable
final JFreeChart chart = ChartFactory.createLineChart(null,
categoryLabel, "Build time", dataset,
PlotOrientation.VERTICAL,
true, false, false);
chart.setBackgroundPaint(Color.white);
// change the auto tick unit selection to integer units only
final CategoryPlot plot = chart.getCategoryPlot();
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setStandardTickUnits(createWordedTimeTickUnits());
// rotate X dates
final CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
// set bar colors
final LineAndShapeRenderer line = (LineAndShapeRenderer) plot.getRenderer();
line.setSeriesPaint(0, Color.BLUE);
line.setStroke(DEFAULT_LINE_STROKE);
// write to reposnce
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
ChartUtilities.writeChartAsPNG(out, chart, IMG_WIDTH, IMG_HEIGHT, info);
}
示例13: createDayOfWeekBreakageDistributionChart
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
public static void createDayOfWeekBreakageDistributionChart(final SortedMap stats, final String categoryLabel, final OutputStream out) throws IOException {
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (final Iterator iter = stats.entrySet().iterator(); iter.hasNext();) {
final Map.Entry entry = (Map.Entry) iter.next();
final Integer dayOfWeek = (Integer) entry.getKey();
final BuildStatistics bst = (BuildStatistics) entry.getValue();
dataset.addValue(new Integer(bst.getFailedBuilds()), "Failed builds", new ComparableDayOfWeek(dayOfWeek));
}
// create the chart object
// This generates a stacked bar - more suitable
final JFreeChart chart = ChartFactory.createStackedBarChart(null,
categoryLabel, "Builds", dataset,
PlotOrientation.VERTICAL,
true, false, false);
chart.setBackgroundPaint(Color.white);
// change the auto tick unit selection to integer units only
final CategoryPlot plot = chart.getCategoryPlot();
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// set bar colors
final BarRenderer bar = (BarRenderer) plot.getRenderer();
bar.setItemMargin(0); // reduce the width between the bars.
bar.setSeriesPaint(0, Color.RED); // first bar
// write to reposnce
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
ChartUtilities.writeChartAsPNG(out, chart, IMG_WIDTH, IMG_HEIGHT, info);
}
示例14: toByteArray
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
public byte[] toByteArray() {
final ByteArrayOutputStream tmpStream = new ByteArrayOutputStream();
try {
ChartUtilities.writeChartAsPNG(tmpStream, myDelegate, myWidth, myHeight);
} catch (final IOException anException) {
// TODO Something!!
}
return tmpStream.toByteArray();
}
示例15: handleRequest
import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
String type = request.getParameter("type");
CategoryDataset dataset = createDataset(type);
JFreeChart chart = createChart(dataset, request);
int imageHeight = Math.max(IMAGE_MIN_HEIGHT, 15 * dataset.getColumnCount());
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, imageHeight);
return null;
}