Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jfree图表在图像上绘制绘图_Java_Image_Jfreechart - Fatal编程技术网

Java jfree图表在图像上绘制绘图

Java jfree图表在图像上绘制绘图,java,image,jfreechart,Java,Image,Jfreechart,我正在使用jfree图表绘制一些定位点 问题是图表是在灰色表面上绘制的,而不是在我的平面图上。所以我尝试使用背景图像,但这将图像放在背景中,无法使用,因为我需要它 我想用一张图片来代替灰色背景。我该怎么做 我使用图表面板在上面绘制图表。问题是,这只允许颜色作为背景,而不允许图像。我试着给图表设置一个图片,如下面的代码所示,但这只设置了背景图像,并在前景的灰色区域绘制图表 JFreeChart chart = ChartFactory.createScatterPlot("XY Chart", /

我正在使用jfree图表绘制一些定位点

问题是图表是在灰色表面上绘制的,而不是在我的平面图上。所以我尝试使用背景图像,但这将图像放在背景中,无法使用,因为我需要它

我想用一张图片来代替灰色背景。我该怎么做

我使用图表面板在上面绘制图表。问题是,这只允许颜色作为背景,而不允许图像。我试着给图表设置一个图片,如下面的代码所示,但这只设置了背景图像,并在前景的灰色区域绘制图表

JFreeChart chart = ChartFactory.createScatterPlot("XY Chart", // Title
                "x-axis", // x-axis Label
                "y-axis", // y-axis Label
                dataset, // Dataset
                PlotOrientation.VERTICAL, // Plot Orientation
                false, // Show Legend
                false, // Use tooltips
                false // Configure chart to generate URLs?
                );    
BufferedImage image = null;
        try {
            File url = new File(System.getProperty("user.dir").toString()+"\\1.jpg");
            image = ImageIO.read(url);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        chart.setBackgroundImage(image);
我试过使用jfreechart-1.0.19。为了避免灰色背景,更改图形区域的透明度有助于注意折线图。getPlot.setBackgroundAlpha0;:

借助这个技巧,我得到了:


你们应该在你们的问题中添加更多的细节,包括你们的一些代码和一个屏幕截图,如果你们能得到的话,还有一个更好的解释你们希望画什么。我想你们是在面板上画的。尝试设置面板的背景,然后在其上绘制。
public class MyChart extends ApplicationFrame {
    public MyChart() throws Exception {
        super("My Chart");

        final XYSeries series1 = new XYSeries("First");
        series1.add(1.0, 1.0);
        series1.add(2.0, 4.0);
        series1.add(3.0, 3.0);

        final XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(series1);

        JFreeChart chart = ChartFactory.createScatterPlot("XY Chart", // Title
                "x-axis", // x-axis Label
                "y-axis", // y-axis Label
                dataset, // Dataset
                PlotOrientation.VERTICAL, // Plot Orientation
                false, // Show Legend
                false, // Use tooltips
                false // Configure chart to generate URLs?
        );
        BufferedImage image = null;
        File url = new File("/home/me/Pictures/test.png");
        image = ImageIO.read(url);
        chart.setBackgroundImage(image);
        chart.getPlot().setBackgroundAlpha(0);

        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);
    }

    public static void main(String args[]) throws Exception {
        final MyChart myChart = new MyChart();
        myChart.pack();
        RefineryUtilities.centerFrameOnScreen(myChart);
        myChart.setVisible(true);
    }
}