我有以下java(awt)代碼,我想將它轉換爲jsp.can中的任何一個告訴我如何執行此操作?
我的java類是StackedBarChart1.java
如何將java(awt)代碼轉換爲jsp代碼
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Paint;
import java.awt.Rectangle;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.LegendItem;
import org.jfree.chart.LegendItemCollection;
import org.jfree.chart.axis.SubCategoryAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.GroupedStackedBarRenderer;
import org.jfree.data.KeyToGroupMap;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.GradientPaintTransformType;
import org.jfree.ui.RefineryUtilities;
import org.jfree.ui.StandardGradientPaintTransformer;
public class StackedBarChart1 extends ApplicationFrame {
StackedBarChart1(String titel) {
super(titel);
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
setContentPane(chartPanel);
}
private CategoryDataset createDataset() {
DefaultCategoryDataset result = new DefaultCategoryDataset();
result.addValue(20.3, "Category 1 (D)", "Jan 08");
result.addValue(27.2, "Category 1 (D)", "Feb 08");
result.addValue(19.7, "Category 1 (D)", "Mar 08");
result.addValue(20.7, "Category 1 (D)", "Apr 08");
result.addValue(19.4, "Category 1 (E)", "Jan 08");
result.addValue(10.9, "Category 1 (E)", "Feb 08");
result.addValue(18.4, "Category 1 (E)", "Mar 08");
result.addValue(12.4, "Category 1 (E)", "Apr 08");
result.addValue(16.5, "Category 1 (W)", "Jan 08");
result.addValue(15.9, "Category 1 (W)", "Feb 08");
result.addValue(16.1, "Category 1 (W)", "Mar 08");
result.addValue(14.4, "Category 1 (W)", "Apr 08");
result.addValue(23.3, "Category 2 (D)", "Jan 08");
result.addValue(16.2, "Category 2 (D)", "Feb 08");
result.addValue(28.7, "Category 2 (D)", "Mar 08");
result.addValue(22.7, "Category 2 (D)", "Apr 08");
result.addValue(12.7, "Category 2 (E)", "Jan 08");
result.addValue(17.9, "Category 2 (E)", "Feb 08");
result.addValue(12.6, "Category 2 (E)", "Mar 08");
result.addValue(14.6, "Category 2 (E)", "Mar 08");
result.addValue(15.4, "Category 2 (W)", "Jan 08");
result.addValue(21.0, "Category 2 (W)", "Feb 08");
result.addValue(11.1, "Category 2 (W)", "Mar 08");
result.addValue(16.1, "Category 2 (W)", "Apr 08");
result.addValue(11.9, "Category 3 (D)", "Jan 08");
result.addValue(31.0, "Category 3 (D)", "Feb 08");
result.addValue(22.7, "Category 3 (D)", "Mar 08");
result.addValue(18.7, "Category 3 (D)", "Apr 08");
result.addValue(15.3, "Category 3 (E)", "Jan 08");
result.addValue(14.4, "Category 3 (E)", "Feb 08");
result.addValue(25.3, "Category 3 (E)", "Mar 08");
result.addValue(16.3, "Category 3 (E)", "Apr 08");
result.addValue(23.9, "Category 3 (W)", "Jan 08");
result.addValue(19.0, "Category 3 (W)", "Feb 08");
result.addValue(10.1, "Category 3 (W)", "Mar 08");
result.addValue(18.1, "Category 3 (W)", "Apr 08");
return result;
}
private JFreeChart createChart(final CategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createStackedBarChart(
"Referral Click Analysis (Stacked Bar Chart)", "Category", "Value", dataset,
PlotOrientation.VERTICAL, true, true, false);
chart.setBackgroundPaint(new Color(249, 231, 236));
GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
KeyToGroupMap map = new KeyToGroupMap("G1");
map.mapKeyToGroup("Category 1 (D)", "G1");
map.mapKeyToGroup("Category 1 (E)", "G1");
map.mapKeyToGroup("Category 1 (W)", "G1");
map.mapKeyToGroup("Category 2 (D)", "G2");
map.mapKeyToGroup("Category 2 (E)", "G2");
map.mapKeyToGroup("Category 2 (W)", "G2");
map.mapKeyToGroup("Category 3 (D)", "G3");
map.mapKeyToGroup("Category 3 (E)", "G3");
map.mapKeyToGroup("Category 3 (W)", "G3");
renderer.setSeriesToGroupMap(map);
renderer.setItemMargin(0.0);
Paint p1 = new GradientPaint(
0.0f, 0.0f, new Color(16, 89, 172), 0.0f, 0.0f, new
Color(201, 201, 244));
renderer.setSeriesPaint(0, p1);
renderer.setSeriesPaint(3, p1);
renderer.setSeriesPaint(6, p1);
Paint p2 = new GradientPaint(
0.0f, 0.0f, new Color(10, 144, 40), 0.0f, 0.0f, new
Color(160, 240, 180));
renderer.setSeriesPaint(1, p2);
renderer.setSeriesPaint(4, p2);
renderer.setSeriesPaint(7, p2);
Paint p3 = new GradientPaint(
0.0f, 0.0f, new Color(255, 35, 35), 0.0f, 0.0f, new
Color(255, 180, 180));
renderer.setSeriesPaint(2, p3);
renderer.setSeriesPaint(5, p3);
renderer.setSeriesPaint(8, p3);
renderer.setGradientPaintTransformer(
new StandardGradientPaintTransformer
(GradientPaintTransformType.HORIZONTAL));
SubCategoryAxis domainAxis = new SubCategoryAxis("Category/Month");
domainAxis.setCategoryMargin(0.05);
domainAxis.addSubCategory("Category 1");
domainAxis.addSubCategory("Category 2");
domainAxis.addSubCategory("Category 3");
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setDomainAxis(domainAxis);
plot.setRenderer(renderer);
plot.setFixedLegendItems(createLegendItems());
return chart;
}
private LegendItemCollection createLegendItems() {
LegendItemCollection result = new LegendItemCollection();
LegendItem item1 = new LegendItem("D", "D", "D", "D",
new Rectangle(10, 10), new GradientPaint(0.0f, 0.0f,
new Color(16, 89, 172), 0.0f, 0.0f, new Color(201, 201, 244)));
LegendItem item2 = new LegendItem("E", "E", "E", "E",
new Rectangle(10, 10), new GradientPaint(0.0f, 0.0f,
new Color(10, 144, 40), 0.0f, 0.0f, new Color(160, 240, 180)));
LegendItem item3 = new LegendItem("W", "W", "W", "W",
new Rectangle(10, 10), new GradientPaint(0.0f, 0.0f,
new Color(255, 35, 35), 0.0f, 0.0f, new Color(255, 180, 180)));
result.add(item1);
result.add(item2);
result.add(item3);
return result;
}
public static void main(final String[] args) {
final StackedBarChart1 demo = new StackedBarChart1("Referral Click Analysis ");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
感謝
Yugal