本文整理汇总了Java中org.knowm.xchart.BitmapEncoder类的典型用法代码示例。如果您正苦于以下问题:Java BitmapEncoder类的具体用法?Java BitmapEncoder怎么用?Java BitmapEncoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitmapEncoder类属于org.knowm.xchart包,在下文中一共展示了BitmapEncoder类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
@Override
public PNGImageNotebookOutput convert(Object object) {
Chart chart = (Chart) object;
byte[] bt;
try {
bt = BitmapEncoder.getBitmapBytes(chart, BitmapEncoder.BitmapFormat.PNG);
Base64.getEncoder().encodeToString(bt);
return new PNGImageNotebookOutput(Base64.getEncoder().encodeToString(bt));
} catch (IOException ex) {
Logger.getLogger(ChartToPNGNotebookConverter.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
示例2: plot99
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
private void plot99(List<Double> xData, List<Double> yData) throws IOException {
XYChart chart = buildCommonChart();
/*
* This shows only the > 90 percentile, so set te minimum
* accordingly.
*/
chart.getStyler().setXAxisMin(99.0);
// Series
XYSeries series = chart.addSeries(chartProperties.getSeriesName(), xData, yData);
series.setLineColor(XChartSeriesColors.BLUE);
series.setMarkerColor(Color.LIGHT_GRAY);
series.setMarker(SeriesMarkers.NONE);
series.setLineStyle(SeriesLines.SOLID);
BitmapEncoder.saveBitmap(chart, baseName + "_99.png", BitmapEncoder.BitmapFormat.PNG);
}
示例3: plot90
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
private void plot90(List<Double> xData, List<Double> yData) throws IOException {
XYChart chart = buildCommonChart();
/*
* This shows only the > 90 percentile, so set te minimum
* accordingly.
*/
chart.getStyler().setXAxisMin(90.0);
// Series
XYSeries series = chart.addSeries(chartProperties.getSeriesName(), xData, yData);
series.setLineColor(XChartSeriesColors.BLUE);
series.setMarkerColor(Color.LIGHT_GRAY);
series.setMarker(SeriesMarkers.NONE);
series.setLineStyle(SeriesLines.SOLID);
BitmapEncoder.saveBitmap(chart, baseName + "_90.png", BitmapEncoder.BitmapFormat.PNG);
}
示例4: plotAll
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
private void plotAll(List<Double> xData, List<Double> yData) throws IOException {
// Create Chart
XYChart chart = buildCommonChart();
/*
* This shows almost everything so set te minimum
* accordingly.
*/
chart.getStyler().setXAxisMin(5.0);
// Series
XYSeries series = chart.addSeries(chartProperties.getSeriesName(), xData, yData);
series.setLineColor(XChartSeriesColors.BLUE);
series.setMarkerColor(Color.LIGHT_GRAY);
series.setMarker(SeriesMarkers.NONE);
series.setLineStyle(SeriesLines.SOLID);
BitmapEncoder.saveBitmap(chart, baseName + "_all.png", BitmapEncoder.BitmapFormat.PNG);
}
示例5: saveChart
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
private void saveChart(XYChart chart, String filename) {
try {
String base = "src/test/charts";
String fullPath = String.format("%s/%s", base, filename);
File f = new File(fullPath);
f.getParentFile().mkdirs();
BitmapEncoder.saveBitmapWithDPI(chart, fullPath, BitmapEncoder.BitmapFormat.PNG, 300);
}
catch (IOException e) {
e.printStackTrace();
}
}
示例6: afterReportInit
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
@Override
public void afterReportInit() throws JRScriptletException
{
try
{
XYChart xyChart = new XYChartBuilder()
.width(515)
.height(400)
.title("Fruits Order")
.xAxisTitle("Day of Week")
.yAxisTitle("Quantity (t)")
.build();
xyChart.addSeries("Apples", new double[] { 1, 3, 5}, new double[] {4, 10, 7});
xyChart.addSeries("Bananas", new double[] { 1, 2, 3, 4, 5}, new double[] {6, 8, 4, 4, 6});
xyChart.addSeries("Cherries", new double[] { 1, 3, 4, 5}, new double[] {2, 6, 1, 9});
XYStyler styler = xyChart.getStyler();
styler.setLegendPosition(Styler.LegendPosition.InsideNW);
styler.setAxisTitlesVisible(true);
styler.setDefaultSeriesRenderStyle(XYSeries.XYSeriesRenderStyle.Area);
styler.setChartBackgroundColor(Color.WHITE);
BufferedImage bufferedImage = BitmapEncoder.getBufferedImage(xyChart);
super.setVariableValue("ChartImage", bufferedImage);
}
catch(Exception e)
{
throw new JRScriptletException(e);
}
}
示例7: savePlotToFile
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
public void savePlotToFile(String path) {
try {
BitmapEncoder.saveBitmapWithDPI(getChart(), path, BitmapFormat.PNG, 500);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例8: saveChart
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
public static void saveChart(Chart chart, String name) {
try {
/* TODO: Maybe change output folder location */
BitmapEncoder.saveBitmapWithDPI(chart, "/tmp/" + name + ".png", BitmapEncoder.BitmapFormat.PNG, 300);
} catch (IOException e) {
e.printStackTrace();
}
}
示例9: chartGenerated
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
protected static void chartGenerated(CategoryChart chart, String writeLocation) throws IOException {
if (StringUtils.isNullOrEmpty(writeLocation)) {
new SwingWrapper<CategoryChart>(chart).displayChart();
System.in.read();
} else {
BitmapEncoder.saveBitmap(chart, writeLocation, BitmapFormat.PNG);
}
}
示例10: saveChart
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
public void saveChart(String fileName, BitmapFormat format) throws IOException {
for (String chart : this.charts.keySet()) {
BitmapEncoder.saveBitmap(this.charts.get(chart), fileName + "_" + chart, format);
}
}
示例11: copy
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
protected void copy(JRPrintImage image)
{
dataset.finishDataset();
JRComponentElement element = fillContext.getComponentElement();
XYChart xyChart = new XYChartBuilder()
.width(element.getWidth())
.height(element.getHeight())
.title(chartTitle == null ? "" : chartTitle)
.xAxisTitle(xAxisTitle == null ? "" : xAxisTitle)
.yAxisTitle(yAxisTitle == null ? "" : yAxisTitle)
.build();
XYStyler styler = xyChart.getStyler();
styler.setLegendPosition(Styler.LegendPosition.InsideNE);
styler.setAxisTitlesVisible(true);
styler.setDefaultSeriesRenderStyle(XYSeries.XYSeriesRenderStyle.Area);
styler.setChartBackgroundColor(element.getBackcolor() == null ? Color.WHITE : element.getBackcolor());
List<Comparable<?>> xySeriesNames = dataset.getXYSeriesNames();
Map<Comparable<?>, XYSeriesData> xySeriesMap = dataset.getXYSeriesMap();
if(xySeriesMap != null && !xySeriesMap.isEmpty())
{
int i = 0;
for(Comparable<?> name : xySeriesNames)
{
XYSeriesData data = xySeriesMap.get(name);
org.knowm.xchart.XYSeries series = xyChart.addSeries(name.toString(), data.getXData(), data.getYData());
Color color = data.getColor();
if(color != null)
{
series.setLineColor(color);
styler.getSeriesColors()[i] = color;
//series.setFillColor(color);
}
i++;
}
}
try
{
BufferedImage img = BitmapEncoder.getBufferedImage(xyChart);
Renderable renderable = RendererUtil
.getInstance(fillContext.getFiller().getJasperReportsContext())
.getRenderable(img, ImageTypeEnum.PNG, OnErrorTypeEnum.ERROR);
image.setRenderer(renderable);
}
catch(Exception e)
{
throw new JRRuntimeException(e);
}
}
示例12: saveBitmap
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
public static void saveBitmap(Chart chart, OutputStream targetStream, BitmapFormat bitmapFormat)
throws IOException {
BufferedImage bufferedImage = BitmapEncoder.getBufferedImage(chart);
ImageIO.write(bufferedImage, bitmapFormat.toString().toLowerCase(), targetStream);
}
示例13: main
import org.knowm.xchart.BitmapEncoder; //导入依赖的package包/类
/**
* @param args Command line arguments.
* @throws SecurityException
* Invoking command:
java org.uma.jmetal.runner.multiobjective.NSGAIIMeasuresRunner problemName [referenceFront]
*/
public static void main(String[] args)
throws JMetalException, InterruptedException, IOException {
DoubleProblem problem;
Algorithm<List<DoubleSolution>> algorithm;
MutationOperator<DoubleSolution> mutation;
String referenceParetoFront = "" ;
String problemName ;
if (args.length == 1) {
problemName = args[0];
} else if (args.length == 2) {
problemName = args[0] ;
referenceParetoFront = args[1] ;
} else {
problemName = "org.uma.jmetal.problem.multiobjective.zdt.ZDT4";
referenceParetoFront = "jmetal-problem/src/test/resources/pareto_fronts/ZDT4.pf" ;
}
problem = (DoubleProblem) ProblemUtils.<DoubleSolution> loadProblem(problemName);
BoundedArchive<DoubleSolution> archive = new CrowdingDistanceArchive<DoubleSolution>(100) ;
double mutationProbability = 1.0 / problem.getNumberOfVariables() ;
double mutationDistributionIndex = 20.0 ;
mutation = new PolynomialMutation(mutationProbability, mutationDistributionIndex) ;
int maxIterations = 250 ;
int swarmSize = 100 ;
algorithm = new SMPSOBuilder(problem, archive)
.setMutation(mutation)
.setMaxIterations(maxIterations)
.setSwarmSize(swarmSize)
.setRandomGenerator(new MersenneTwisterGenerator())
.setSolutionListEvaluator(new SequentialSolutionListEvaluator<DoubleSolution>())
.setVariant(SMPSOBuilder.SMPSOVariant.Measures)
.build();
/* Measure management */
MeasureManager measureManager = ((SMPSOMeasures)algorithm).getMeasureManager() ;
BasicMeasure<List<DoubleSolution>> solutionListMeasure = (BasicMeasure<List<DoubleSolution>>) measureManager
.<List<DoubleSolution>>getPushMeasure("currentPopulation");
CountingMeasure iterationMeasure = (CountingMeasure) measureManager.<Long>getPushMeasure("currentIteration");
ChartContainer chart = new ChartContainer(algorithm.getName(), 200);
chart.setFrontChart(0, 1, referenceParetoFront);
chart.setVarChart(0, 1);
chart.initChart();
solutionListMeasure.register(new ChartListener(chart));
iterationMeasure.register(new IterationListener(chart));
/* End of measure management */
AlgorithmRunner algorithmRunner = new AlgorithmRunner.Executor(algorithm).execute();
chart.saveChart("./chart", BitmapEncoder.BitmapFormat.PNG);
List<DoubleSolution> population = algorithm.getResult();
long computingTime = algorithmRunner.getComputingTime();
JMetalLogger.logger.info("Total execution time: " + computingTime + "ms");
printFinalSolutionSet(population);
if (!referenceParetoFront.equals("")) {
printQualityIndicators(population, referenceParetoFront);
}
}