I want to change the color of my Chart(Pie) (background Color dataset colors and so on ..) via a button or menu selection klick from an portlet (Vaadin / Liferay portal) . i kinda have no clue how to do that Here is my Servlet :
import org.jfree.data.jdbc.JDBCPieDataset;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.Connection;
public class PieChart extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection connection = null;
try {
Class.forName("org.postgresql.Driver").newInstance();
try {
connection = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/db", "user",
"password");
} catch (SQLException e) {
e.printStackTrace();
}
}
catch (InstantiationException e) {
e.printStackTrace();
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
JDBCPieDataset dataset = new JDBCPieDataset(connection);
try {
dataset.executeQuery("Select * From my_table");
JFreeChart chart = ChartFactory.createPieChart("Pie Chart", dataset, true, false, false);
if (chart != null) {
response.setContentType("image/png");
OutputStream out = response.
getOutputStream();
ChartUtilities.writeChartAsPNG(out, chart, 450, 400);
}
}
catch (SQLException e) {
e.printStackTrace();
}
try {
if(connection != null){connection.close();}
}
catch (SQLException e) {e.printStackTrace();}
}
what i want to do is , to send the Selected Color to the Servlet so the Color changes when i klick on a menu selection ( already have the menu ).
Any guide or similar would be great.
now lets say i want to change the background color of the chart. i would use chart.setBackgroundPaint(Color.blue); in the servlet to change the color manualy . but i want to do it from the portlet this is what i have tryed to do:
PieChart pie;
in the init method i configure the menu and try to send the color on click
final MenuBar.MenuItem config = menubar.addItem("Config", null);
newItem.addItem("PieChart", new Command(){
public void menuSelected(MenuItem selectedItem) {
pie.chart.setBackgroundPaint(Color.blue);
}
});
i use the same to change the background color of a subwindow from another class it works fine but does not seem to work within a servlet .