- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个关于图表 LineChart JavaFX 的好奇问题。
我有这个图表: 在 X 轴上形成“跳跃”的点(如我得分的两个红点所示),因此 JavaFX 在这两点之间画了一条线。如何删除每个“跳转”之间的那条线?
我发布代码:
public class ControllerIndividua {
public static void plotIndividuaFull(String path, Stage stage, String name) {
final NumberAxis xAxisIntensity = new NumberAxis(); //Dichiarazione asseX
final NumberAxis yAxisIntensity = new NumberAxis();//Dichiarazione asseY
DetectionS1.countS1();
//Dichiarazione del tipo di grafico
final LineChart<Number, Number> lineChartIntensity = new LineChart<Number, Number>(xAxisIntensity,yAxisIntensity);
ArrayList<Double> extractedData; //Lista dei valori dello dell' intensità
ArrayList<Double> extractedTime; //Lista del tempo
ArrayList<Double> extractedS1; //Lista del tempo
ArrayList<Double> extractedS1Time; //Lista del tempo
//Gestione e settaggio del grafico
lineChartIntensity.getData().clear();
try {
//Popolamento delle liste
extractedTime = IntensityExtractor.pointsTime();
extractedData = IntensityExtractor.pointsIntensity();
extractedS1 = DetectionS1.S1pitch();
extractedS1Time = DetectionS1.pointsS1Time();
XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
XYChart.Series<Number, Number> seriesS1 = new XYChart.Series<Number, Number>(); //Creazione seconda serie
series.setName("Intensità di:\t" + name.toUpperCase());
for (int j = 0; j < extractedS1.size(); j++) {
seriesS1.getData().add(new XYChart.Data<Number, Number>(extractedS1Time.get(j), extractedS1.get(j)));
lineChartIntensity.getStyleClass().add("CSSintensity");
}
//Creazione finestra e stampa del grafico
Scene scene = new Scene(lineChartIntensity, 1000, 600);
lineChartIntensity.getData().addAll(series,seriesS1);
scene.getStylesheets().add("application/application.css");
stage.setScene(scene);
stage.show();
} catch (java.lang.Exception e) {
e.printStackTrace();
}
}
}
有人也知道我该怎么做吗?
提前谢谢大家。
最佳答案
这是一个老问题,有一个公认的答案,但我遇到了它并且很好奇。我想知道是否可以在 LineChart 中添加间隙(至少无需创建自定义图表实现)。事实证明是有的。该解决方案有点老套且脆弱。它涉及获取 Path
通过使用 XYChart.Series.getNode()
并操作 PathElement
的列表s。下面的代码给出了一个例子:
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
LineChart<Number, Number> chart = new LineChart<>(new NumberAxis(), new NumberAxis());
chart.getXAxis().setLabel("X");
chart.getYAxis().setLabel("Y");
chart.setLegendVisible(false);
chart.getData().add(new XYChart.Series<>());
for (int x = 0; x <= 10; x++) {
chart.getData().get(0).getData().add(new XYChart.Data<>(x, Math.pow(x, 2)));
}
/*
* Had to wrap the call in a Platform.runLater otherwise the Path was
* redrawn after the modifications are made.
*/
primaryStage.setOnShown(we -> Platform.runLater(() -> {
Path path = (Path) chart.getData().get(0).getNode();
LineTo lineTo = (LineTo) path.getElements().get(8);
path.getElements().set(8, new MoveTo(lineTo.getX(), lineTo.getY()));
}));
primaryStage.setScene(new Scene(new StackPane(chart), 500, 300));
primaryStage.setTitle("LineChart Gap");
primaryStage.show();
}
}
此代码产生以下结果:
这是可能的,因为 PathElement
的 ObservableList
似乎是 MoveTo
接下来是一堆LineTo
s。我只是选择了一个 LineTo
并将其替换为 MoveTo
到相同的坐标。然而,我还没有完全弄清楚 LineTo
的哪个索引与哪个 XYChart.Data
匹配,并随机选择了 8
作为示例。
此解决方案存在几个问题。第一个也是明显的一点是,这依赖于 LineChart 的内部实现。第二个是真正的脆弱性的来源。对数据的任何更改,无论是坐标轴的值范围、图表的宽度或高度,还是导致图表自身重绘的几乎任何内容都会导致重新计算路径并重新绘制。这意味着,如果您使用此解决方案,则每次图表重新绘制时都必须重新应用修改。
关于javafx - LineChart FX - 删除实线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42424166/
我正在尝试使用立方图制作 LineChart。结果如下面的截图所示:三次贝塞尔曲线显示错误并有“尖峰”。有人可以帮我让它正确显示吗? 这是我的配置: LineDataSet lineD
Tag Library supports namespace: http://primefaces. org/ui,但没有为名称定义标签:lineChart
我想使用 primefaces 5.1 创建折线图。但在加载我的 xhtml 页面时,我收到错误消息“ Tag Library supports namespace: http://primeface
默认情况下,在 chart.js 中显示折线图时.工具提示显示存在的所有数据集的值。 当我们将鼠标悬停在该数据集点而不是所有数据集点上时,如何仅显示一个数据集点的值 最佳答案 nearest工具提示选
这个图表显示了问题: 我有计算数据和绘制图表的 JavaFX 程序,但为什么点连接不正确?我尝试了很多东西,甚至创建了两个单独的系列,但它不起作用。 public void createScatter
我知道在 Using Google Visualization API, how to turn off tooltips for a single column? 之前已经问过这个问题,但我没有得到
我想更新 LineChart 图例的样式,我在具有相应系列类的节点上使用 setStyle。 String color = .... XYChart.Series series = new XYCha
这是界面代码: @Override public void start(Stage primaryStage){ NumberAxis xAxis = new NumberAxis();
这个问题已经有答案了: JavaFX BarChart, Set Series Color by Series Name (1 个回答) 已关闭 5 年前。 此帖子已于 7 个月前编辑并提交审核,但未
我在从折线图中删除数据时遇到问题。我写了一个绘制图表的程序,点击按钮后的 Action 完成图表数据。 dataSeries1.getData().removeAll(); () {
我有这个代码: @Override public void start(Stage primaryStage){ NumberAxis xAxis = new NumberAxis();
刚刚遇到了 javafx.scene.chart.LineChart 的问题。当使用高于 5E13 的 Double 值填充图表数据时,该系列恰好消失(参见屏幕截图)。 之前 之后 以防万一:我使用以
我正在尝试将 javaFX LineChart 保存为 PNG,我希望背景是透明的。如果我这样做: SnapshotParameters spa = new SnapshotParameters();
我正在尝试使用 JavaFX 中的 LineChart 向用户显示数据。我有一个 Float 数组(不是原语,是对象,如 Float[] 中所示),可以随时添加,长度可以在 512 到 4096 点之
我正在尝试在 JavaFX 中创建折线图。此折线图应该有一个轴 (y) 与数字和另一个轴 (x) 与日期。日期范围应该由用户使用两个日期选择器来选择。现在这是我的问题:折线图只有类别和数字轴。有什么方
我正在使用这个图表库 https://github.com/danielgindi/Charts在我的申请中。我从中实现了折线图,图例相互重叠。我不确定这里出了什么问题,我确实玩过很多传奇的不同属性,
我正在使用 javascript 在我的 Web 应用程序中显示 Google Visulization LineChart。我怎样才能让它显示垂直网格线?我已经阅读了有关使用 chg 设置它们的信息
我想使用 Recharts 的 LineChart 来显示最多 200 个点的数据集。但是,我只想在小屏幕上显示其中 5 个数据点的点/工具提示/activeDot,因为在智能手机上不再可点击 200
我想在 LineChart 中设置一些值,但出现错误:添加了重复系列,或 NPE(我尝试清除我的系列列表,调用retainAll,但没有任何结果有帮助)在我的 Controller 类中,我存储了我的
我有一个关于图表 LineChart JavaFX 的好奇问题。 我有这个图表: 在 X 轴上形成“跳跃”的点(如我得分的两个红点所示),因此 JavaFX 在这两点之间画了一条线。如何删除每个“跳转
在这个演示中 http://nvd3.org/livecode/index.html#codemirrorNav只需将数据更改为 function() { return [ {
我是一名优秀的程序员,十分优秀!