Hello Friends
package com;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
@Path("helloworld")
public class test {
@GET
@Produces("image/png")
public Response getMessage() throws IOException {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(10, "Profit1", "Jane");
dataset.setValue(10, "Profit2", "Jane");
dataset.setValue(7, "Profit1", "Tom");
dataset.setValue(10, "Profit2", "Tom");
dataset.setValue(8, "Profit1", "Jill");
dataset.setValue(8, "Profit2", "Jill");
dataset.setValue(5, "Profit1", "John");
dataset.setValue(6, "Profit2", "John");
dataset.setValue(1, "Profit1", "Fred");
dataset.setValue(5, "Profit2", "Fred");
final JFreeChart chart = ChartFactory.createBarChart3D(
"Comparison between Salesman", // Chart name
"Salesman", // X axis label
"Value ($)", // Y axis value
dataset, // data set
PlotOrientation.VERTICAL,
true, true, false);
BufferedImage image = chart.createBufferedImage(600, 600);
ByteArrayOutputStream byteArray = new ByteArrayOutputStream() ;
ChartUtilities.writeBufferedImageAsPNG(byteArray, image) ;
return Response.ok(new ByteArrayInputStream(byteArray.toByteArray())).build();
}
}
package com;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
@Path("helloworld")
public class test {
@GET
@Produces("image/png")
public Response getMessage() throws IOException {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(10, "Profit1", "Jane");
dataset.setValue(10, "Profit2", "Jane");
dataset.setValue(7, "Profit1", "Tom");
dataset.setValue(10, "Profit2", "Tom");
dataset.setValue(8, "Profit1", "Jill");
dataset.setValue(8, "Profit2", "Jill");
dataset.setValue(5, "Profit1", "John");
dataset.setValue(6, "Profit2", "John");
dataset.setValue(1, "Profit1", "Fred");
dataset.setValue(5, "Profit2", "Fred");
final JFreeChart chart = ChartFactory.createBarChart3D(
"Comparison between Salesman", // Chart name
"Salesman", // X axis label
"Value ($)", // Y axis value
dataset, // data set
PlotOrientation.VERTICAL,
true, true, false);
BufferedImage image = chart.createBufferedImage(600, 600);
ByteArrayOutputStream byteArray = new ByteArrayOutputStream() ;
ChartUtilities.writeBufferedImageAsPNG(byteArray, image) ;
return Response.ok(new ByteArrayInputStream(byteArray.toByteArray())).build();
}
}