简体   繁体   English

无法在 Java Swing 中映射图像

[英]Not able to map image in Java Swing

I have a class with the name of ImageMapDemo7 , and I want to map an image with this program;我有一个名为ImageMapDemo7的类,我想用这个程序映射一个图像; but I'm getting an error.但我遇到了一个错误。 I have all packages.我有所有的包裹。 Is there any SampleXYDataset2 class in JFreeChart or not? JFreeChart 中是否有任何SampleXYDataset2类?

The code is this:代码是这样的:

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYDataset;

/**
 * A demo showing how to create an HTML image map for a scatter plot.
 *
 */
public class ImageMapDemo7 {

    /**
     * Default constructor.
     */
    public ImageMapDemo7() {
        super();
    }


    public static void main(final String[] args) {

       final XYDataset data = new SampleXYDataset2();
        final JFreeChart chart = ChartFactory.createScatterPlot(
            "Scatter Plot Demo",
            "X", "Y", 
            data, 
            PlotOrientation.VERTICAL,
            true, 
            true, 
            false
        );
//      final NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis();
        domainAxis.setAutoRangeIncludesZero(false);
        chart.setBackgroundPaint(java.awt.Color.white);

        // save it to an image

       try {
            final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
            final File file1 = new File("image1.jpg");
            ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

            // write an HTML page incorporating the image with an image map
            final File file2 = new File("scatter100.html");
            final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
            final PrintWriter writer = new PrintWriter(out);
            writer.println("<HTML>");
            writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
            writer.println("<BODY>");
//            ChartUtilities.writeImageMap(writer, "chart", info);
            writer.println("<IMG SRC=\"image1.jpg\" "
                           + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
            writer.println("</BODY>");
            writer.println("</HTML>");
            writer.close();

        }
        catch (IOException e) {
            System.out.println(e.toString());
        }

    }

}

The error is this:错误是这样的:

ImageMapDemo7.java:37: error: cannot find symbol
       final XYDataset data = new SampleXYDataset2();
                                  ^
  symbol:   class SampleXYDataset2
  location: class ImageMapDemo7

You need to add jfreechart-1.0.1-demo.jar in your classpath.您需要在类路径中添加 jfreechart-1.0.1-demo.jar。 Import statement should be added.应添加导入语句。 Jar can be downloaded from this link Jar 可以从这个链接下载

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM