Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.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 当图形非常大时,为什么x轴消失了_Java_Javafx_Jfreechart - Fatal编程技术网

Java 当图形非常大时,为什么x轴消失了

Java 当图形非常大时,为什么x轴消失了,java,javafx,jfreechart,Java,Javafx,Jfreechart,我正在尝试使用JFreeChart加载大型图形。但是,当缓冲图像大于某个大小时,X轴有问题。这些值在X轴上消失。这可以在图像的第三个图表中看到 如果您能帮我解决这个问题,我将不胜感激 import java.awt.Color; import java.awt.image.BufferedImage; import java.util.ArrayList; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeCha

我正在尝试使用
JFreeChart
加载大型图形。但是,当缓冲图像大于某个大小时,X轴有问题。这些值在X轴上消失。这可以在图像的第三个图表中看到


如果您能帮我解决这个问题,我将不胜感激

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import javafx.application.Application;
import javafx.concurrent.Task;
import javafx.embed.swing.SwingFXUtils;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Program2 extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        try {
            StackPane p = new StackPane();
            primaryStage.setTitle("Chart Application");
            Label loader = new Label("Loading...");
            loader.setGraphic(new ImageView(new Image("https://media.giphy.com/media/FmcNeI0PnsAKs/giphy.gif")));
            loader.setFont(new javafx.scene.text.Font(35));
            p.setStyle("-fx-background: #FFFFFF;");
            p.getChildren().add(loader);
            StackPane.setAlignment(loader, Pos.CENTER);

            Scene scene = new Scene(p, 600, 600);
            primaryStage.setScene(scene);
            primaryStage.setMaximized(true);

            Task<ArrayList<ImageView>> loadInitial = new Task<ArrayList<ImageView>>() {
                @Override
                public ArrayList<ImageView> call() {
                    ArrayList<ImageView> images = new ArrayList<ImageView>();
                    XYSeries data = new XYSeries(1);

                    for(int j = 0; j <= 100; j += 2) {
                        data.add(j, -0.2);
                        data.add(j, 1);
                        data.add(j + 1, 1);
                        data.add(j + 1, -0.2);
                    }

                    XYSeriesCollection dataset = new XYSeriesCollection(data);

                    JFreeChart chart = ChartFactory.createXYAreaChart("", "", "", dataset, PlotOrientation.VERTICAL, false, false, false);
                    chart.setBackgroundPaint(Color.WHITE);
                    chart.setBorderVisible(false);
                    chart.setAntiAlias(true);

                    XYPlot plot = (XYPlot) chart.getPlot();

                    ValueAxis range = plot.getRangeAxis();
                    range.setLowerMargin(0);
                    range.setUpperMargin(0);
                    range.setVisible(false);

                    ValueAxis domainAxis = plot.getDomainAxis();
                    domainAxis.setLowerMargin(0);
                    domainAxis.setUpperMargin(0);

                    BufferedImage capture = chart.createBufferedImage(1000, 50);
                    ImageView imageView = new ImageView();
                    Image chartImg = SwingFXUtils.toFXImage(capture, null);
                    imageView.setImage(chartImg);

                    images.add(imageView);

                    BufferedImage capture2 = chart.createBufferedImage(10000, 50);
                    ImageView imageView2 = new ImageView();
                    Image chartImg2 = SwingFXUtils.toFXImage(capture2, null);
                    imageView2.setImage(chartImg2);

                    images.add(imageView2);

                    BufferedImage capture3 = chart.createBufferedImage(100000, 50);
                    ImageView imageView3 = new ImageView();
                    Image chartImg3 = SwingFXUtils.toFXImage(capture3, null);
                    imageView3.setImage(chartImg3);

                    images.add(imageView3);

                    return images;
                }
            };

            loadInitial.setOnSucceeded(e -> {
                VBox images = new VBox();
                ArrayList<ImageView> result = loadInitial.getValue();
                for(ImageView image : result) {
                    images.getChildren().add(image);
                }

                ScrollPane scrollPane = new ScrollPane(images);
                scrollPane.setStyle("-fx-background: #FFFFFF;");

                scene.setRoot(scrollPane);
            });

            new Thread(loadInitial).start();

            primaryStage.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
导入java.awt.Color;
导入java.awt.image.buffereImage;
导入java.util.ArrayList;
导入org.jfree.chart.ChartFactory;
导入org.jfree.chart.JFreeChart;
导入org.jfree.chart.axis.ValueAxis;
导入org.jfree.chart.plot.PlotOrientation;
导入org.jfree.chart.plot.XYPlot;
导入org.jfree.data.xy.XYSeries;
导入org.jfree.data.xy.XYSeriesCollection;
导入javafx.application.application;
导入javafx.concurrent.Task;
导入javafx.embed.swing.SwingFXUtils;
导入javafx.geometry.Pos;
导入javafx.scene.scene;
导入javafx.scene.control.Label;
导入javafx.scene.control.ScrollPane;
导入javafx.scene.image.image;
导入javafx.scene.image.ImageView;
导入javafx.scene.layout.StackPane;
导入javafx.scene.layout.VBox;
导入javafx.stage.stage;
公共类程序2扩展了应用程序{
公共静态void main(字符串[]args){
发射(args);
}
@凌驾
公共无效开始(阶段primaryStage){
试一试{
StackPane p=新的StackPane();
primaryStage.setTitle(“图表应用程序”);
标签加载器=新标签(“加载…”);
loader.setGraphic(新图像视图(新图像https://media.giphy.com/media/FmcNeI0PnsAKs/giphy.gif")));
setFont(新的javafx.scene.text.Font(35));
p、 setStyle(“-fx背景:#FFFFFF;”);
p、 getChildren().add(加载器);
StackPane.setAlignment(装载机,位置中心);
场景=新场景(p,600,600);
初级阶段。场景(场景);
primaryStage.setMaximized(真);

任务

导致此问题的原因是
记号数
(轴上的标记)超过了
值轴。当图形如此大时,最大记号数

为了解决此问题,您可以使用增加的
ValueAxis.MAXIMUM\u TICK\u COUNT
值重新生成包,或者您可以编写一个方法,允许您设置最大TICK COUNT,然后重新生成包。这将允许您在不同的java文件中设置TICK的数量。这可以是一种方法,例如
ValueAxis.setMaximumTickCount(整数刻度)

取自

编辑
为了实现这一点,我从
org.jfree.chart.axis
ValueAxis.java
NumberAxis.java
编辑了两个文件

更改为
ValueAxis.java
。我在类的底部添加了以下内容

private int maxTicks = MAXIMUM_TICK_COUNT;

public void setMaxTicks(int max) {
    maxTicks = max;
}

public int getMaxTicks() {
    return maxTicks;
}
更改为
NumberAxis.java

957
行和
1052
行中,我将if语句从

if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {

if(计数交叉发布。@垃圾神交叉发布有问题吗?@trashgood很公平。对不起
if (count <= getMaxTicks()) {