多个jfreecharts显示相同的数据

时间:2015-09-25 14:33:23

标签: java jfreechart

我目前正致力于一个游戏统计建模程序(英雄联盟),它输出一个输入玩家名称的条形图,显示关于冠军的杀戮,死亡和助攻的指标。

我的问题是:我有一个类BarChart_AWT,其中包含一个函数display(Player player),可以打印出给定玩家所描述的图形。现在,我正在使用display(Player player)函数:

BarChart_AWT.display(player1);
BarChart_AWT.display(player2);

然而这两个单独的函数调用返回相同的图形,我知道不应该这样。见下面的输出。

Output Graphs

我的课程BarChart_AWT包含在下方。如果有人能帮助我找出我遇到这个问题的原因,我将非常感激。谢谢!

public class BarChart_AWT extends ApplicationFrame
{
    private static final long serialVersionUID = 1L;

    public BarChart_AWT( String applicationTitle , String chartTitle, Vector<championClass> vect )
    {

        super( applicationTitle );        
        JFreeChart barChart = ChartFactory.createBarChart(
            chartTitle,           
            "Champion",            
            "Value",            
            createDataset(vect),          
            PlotOrientation.VERTICAL,           
            true, true, false);

        ChartPanel chartPanel = new ChartPanel( barChart );        
        chartPanel.setPreferredSize(new java.awt.Dimension( 560 , 367 ) );        
        setContentPane( chartPanel ); 
     }

    //Populates graph with data
    private CategoryDataset createDataset( Vector<championClass> cVector)
    {
        final DefaultCategoryDataset dataset = new DefaultCategoryDataset( );

        //Define Bars
        final String kills = "Kills";        
        final String deaths = "Deaths";        
        final String assists = "Assists"; 

        for (Enumeration<championClass> e = cVector.elements(); e.hasMoreElements();)
        {
            championClass current = e.nextElement();
            final String championName = current.getName();
            dataset.addValue(current.getKills(), kills, championName);
            dataset.addValue(current.getDeaths(), deaths, championName);
            dataset.addValue(current.getAssists(), assists, championName);
        }

        return dataset; 
    }

    public static void display(Player player) {
        BarChart_AWT playerChart = new BarChart_AWT("Champion data for: " + player.getName(), "Performance by Champion", player.getVector());
        playerChart.pack( );        
        RefineryUtilities.positionFrameOnScreen(playerChart, 25, 25);       
        playerChart.setVisible( true );
    }
}

0 个答案:

没有答案