JFreechart类柱状图
?? return chart;
}
//返回一个CategoryDataset实例
private static CategoryDataset getDataSet()
{
?? DefaultCategoryDataset dataset = new DefaultCategoryDataset();
?? int total = supportCount+blackballCount;
?? if(total < 1) total = 1;
?? dataset.addValue((double)supportCount/total, "" , "正方(" + supportCount + ")");
?? dataset.addValue((double)blackballCount/total, "" , "反方(" + blackballCount + ")");
?? //dataset.addValue(supportCount, "佛山" , "正方");
?? //dataset.addValue(blackballCount, "佛山" , "反方");
?? //dataset.addValue(supportCount , "广州" , "正方");
?? //dataset.addValue(blackballCount , "广州" , "反方");
?? return dataset;
}
public String showVoteChart()
{
?? if("support".equals(voteType))
?? {
??? supportCount++;
?? }
?? else if("blackball".equals(voteType))
?? {
??? blackballCount++;
?? }
?? //supportCount = 0;//快速清零,不用重启系统
?? //blackballCount = 0;//快速清零,不用重启系统
?? this.chart = getChart();
?? return SUCCESS;
}
/**
* @return the supportCount
*/
public static int getSupportCount()
{
?? return supportCount;
}
/**
* @return the blackballCount
*/
public static int getBlackballCount()
{
?? return blackballCount;
}
/**
* @return the voteType
*/
public String getVoteType()
{
?? return voteType;
}
/**
* @param supportCount the supportCount to set
*/
public static void setSupportCount(int supportCount)
{
?? VoteChartAction.supportCount = supportCount;
}
/**
* @param blackballCount the blackballCount to set
*/
public static void setBlackballCount(int blackballCount)
{
?? VoteChartAction.blackballCount = blackballCount;
}
/**
* @param voteType the voteType to set
*/
public void setVoteType(String voteType)
{
?? this.voteType = voteType;
}
}
=============================================
struts 配置
==========================
<package name="chart" extends="jfreechart-default">
?? <action name="show_vote_chart" method="showVoteChart">
??? <result name="success" type="chart">
???? <param name="width">420</param>
???? <param name="height">250</param>
??? </result>
?? </action>
</package>
========================
页面代码
========================
<div style="width:420px;height:250px;padding-left:100px;">
??? <iframe id="votechart" name="votechart" src="${base}/chart/show_vote_chart.action" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" style="height:100%;width:100%"></iframe>
?? </div>
?? <div style="width:420px;height:25px;padding-left:100px;text-align:center;font-size:16px;">
??? <a href="#this" onclick="changeChart('support')">支持</a>
??? <a href="#this" onclick="changeChart('blackball')">反对</a>
?? </div>
?? <script type="text/javascript">
??? function changeChart(type)
??? {
???? if(type == "support")
???? {
????? coos.$id("votechart").src = "${base}/chart/show_vote_chart.action?voteType=support";
???? }
???? else if(type == "blackball")
???? {
????? coos.$id("votechart").src = "${base}/chart/show_vote_chart.action?voteType=blackball";
???? }
???
??? }
?? </script>
?? <hr />
引自:http://dreampeter.blog.163.com/blog/static/7980324200965115336881/