
struts2中jfreechart在jsp页面显示
在struts2.2中,如何将在Action中生成的JfreeChart显示在jsp中,希望高手能指导下,谢谢!最好能给个详细的例子...
在struts2.2中,如何将在Action中生成的JfreeChart显示在jsp中,希望高手能指导下,谢谢!最好能给个详细的例子
展开
1个回答
展开全部
package consume.action;
import java.awt.Color;
import java.awt.Font;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.TextAnchor;
import org.springframework.stereotype.Component;
import com.opensymphony.xwork2.ActionSupport;
import consume.model.ShopList;
import consume.model.ShopListHistory;
import consume.service.ShopListHistoryService;
import consume.service.ShopListService;
@Component("barchart")
public class BarChartAction extends ActionSupport{
private JFreeChart chart;
private ShopListHistoryService shopListHistoryService;
private String type;
public JFreeChart getChart()
{
chart=ChartFactory.createBarChart3D(type+"","","",getDataSet(),PlotOrientation.VERTICAL,true,true,false);
chart.setTitle(new TextTitle(type+"",new Font("",Font.ITALIC,22)));
CategoryPlot plot=(CategoryPlot)chart.getPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.pink);
plot.setRangeGridlinePaint(Color.pink);
BarRenderer3D renderer = new BarRenderer3D();
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setBaseItemLabelsVisible(true);
CategoryAxis categoryAxis=plot.getDomainAxis();
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
renderer.setItemLabelAnchorOffset(10D);
categoryAxis.setLabelFont(new Font("����",Font.BOLD,22));
categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
categoryAxis.setTickLabelFont(new Font("����",Font.BOLD,18));
NumberAxis numberAxis=(NumberAxis)plot.getRangeAxis();
numberAxis.setLabelFont(new Font("����",Font.BOLD,22));
return chart;
}
private CategoryDataset getDataSet()
{
DefaultCategoryDataset dataset=new DefaultCategoryDataset();
List<ShopListHistory> shopLists=shopListHistoryService.findByType(type);
Iterator<ShopListHistory> iter=shopLists.iterator();
while(iter.hasNext())
{
ShopListHistory sl=iter.next();
dataset.setValue( sl.getCount(),"",sl.getProname());
}
return dataset;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public ShopListHistoryService getShopListHistoryService() {
return shopListHistoryService;
}
@Resource
public void setShopListHistoryService(
ShopListHistoryService shopListHistoryService) {
this.shopListHistoryService = shopListHistoryService;
}
}
import java.awt.Color;
import java.awt.Font;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.TextAnchor;
import org.springframework.stereotype.Component;
import com.opensymphony.xwork2.ActionSupport;
import consume.model.ShopList;
import consume.model.ShopListHistory;
import consume.service.ShopListHistoryService;
import consume.service.ShopListService;
@Component("barchart")
public class BarChartAction extends ActionSupport{
private JFreeChart chart;
private ShopListHistoryService shopListHistoryService;
private String type;
public JFreeChart getChart()
{
chart=ChartFactory.createBarChart3D(type+"","","",getDataSet(),PlotOrientation.VERTICAL,true,true,false);
chart.setTitle(new TextTitle(type+"",new Font("",Font.ITALIC,22)));
CategoryPlot plot=(CategoryPlot)chart.getPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.pink);
plot.setRangeGridlinePaint(Color.pink);
BarRenderer3D renderer = new BarRenderer3D();
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setBaseItemLabelsVisible(true);
CategoryAxis categoryAxis=plot.getDomainAxis();
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
renderer.setItemLabelAnchorOffset(10D);
categoryAxis.setLabelFont(new Font("����",Font.BOLD,22));
categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
categoryAxis.setTickLabelFont(new Font("����",Font.BOLD,18));
NumberAxis numberAxis=(NumberAxis)plot.getRangeAxis();
numberAxis.setLabelFont(new Font("����",Font.BOLD,22));
return chart;
}
private CategoryDataset getDataSet()
{
DefaultCategoryDataset dataset=new DefaultCategoryDataset();
List<ShopListHistory> shopLists=shopListHistoryService.findByType(type);
Iterator<ShopListHistory> iter=shopLists.iterator();
while(iter.hasNext())
{
ShopListHistory sl=iter.next();
dataset.setValue( sl.getCount(),"",sl.getProname());
}
return dataset;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public ShopListHistoryService getShopListHistoryService() {
return shopListHistoryService;
}
@Resource
public void setShopListHistoryService(
ShopListHistoryService shopListHistoryService) {
this.shopListHistoryService = shopListHistoryService;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询