java生成hadoop结果的图形

lzfw57am  于 2021-05-29  发布在  Hadoop
关注(0)|答案(0)|浏览(237)

我正在尝试使用jfreechart为hadoop的结果生成piechart。这就是我要运行的代码。输出文件是目录中的hdfs "/MSN/result/part-r-00000" .

public class PieChart_AWT extends ApplicationFrame 
{
public PieChart_AWT( String title ) 
{
    super( title ); 
    setContentPane(createDemoPanel( ));
}
private static PieDataset createDataset( ) 
{
    // The name of the file to open.
    String fileName = "hdfs://localhost:9000/MSN/result/part-r-00000";

    // This will reference one line at a time
    String line = null;
    DefaultPieDataset dataset = new DefaultPieDataset( );

    try {Configuration conf=new Configuration( );
    conf.addResource(new Path("/usr/local/hadoop/etc/hadoop/core-site.xml"));
    FileSystem fs1 = FileSystem.get(conf);

    BufferedReader br1 = new BufferedReader(new InputStreamReader(
            fs1.open(new Path(fileName))));
    // FileReader reads text files in the default encoding.

    while((line = br1.readLine()) != null) {    
        String data[]=line.split(",");
        dataset.setValue( data[0], Double.parseDouble(data[1])); 

    }   

    // Always close files.
    br1.close();         
    }
    catch(FileNotFoundException ex) {
        System.out.println(
                "Unable to open file '" + 
                        fileName + "'");                
    }
    catch(IOException ex) {
        System.out.println(
                "Error reading file '" 
                        + fileName + "'");                  
        // Or we could just do this: 
        // ex.printStackTrace();
    }

    return dataset;         
}
private static JFreeChart createChart( PieDataset dataset )
{
    JFreeChart chart = ChartFactory.createPieChart(      
            "Mobile Salesxdass",  // chart title 
            dataset,        // data    
            true,           // include legend   
            true, 
            false);

    return chart;
}
public static JPanel createDemoPanel( )
{
    JFreeChart chart = createChart(createDataset( ) );  
    return new ChartPanel( chart ); 
}
public static void main( String[ ] args )
{
    PieChart_AWT demo = new PieChart_AWT( "Mobile Sales" );  
    demo.setSize( 560 , 367 );    
    RefineryUtilities.centerFrameOnScreen( demo );    
    demo.setVisible( true ); 
}
}

此代码无效。代码有什么变化吗?如果可能的话,请推荐一些在hadoop中生成结果图的替代方法?我得到的错误是:

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题