javafx - 如何在折线图 javafx 中显示所需的 setTickLabelsVisible 数量
问题描述
我正在尝试为股市数据构建时间序列折线图。我正在动态获取输入,并将其绘制在折线图上。
我想要的只是在图表上绘制每个刻度数据,但只想显示所需数量的刻度标签。
例如:假设我在上午 10 点开始构建图表,并且我正在绘制 3 秒,所以在 4 小时后,即下午 1 点,我希望绘制每个刻度,但 Xaxis 上的标签应该是我的选择,比如说只有 4 个刻度标签(10AM、11AM、12AM、1PM)。
请查看所需的图表:
提前非常感谢。:)
代码:
@FXML
private void buttonGraph(ActionEvent event) throws ParseException{
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalTime initTime = LocalTime.now();
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
Session session = cluster.connect("pass_master");
lineChart.getData().clear();
ResultSet results2 = session.execute("select count(*) as ct from pass8 where tkn ="+basic.get(tkn.getText())+" and timestmp <= "+etDate+" and timestmp >= "+stDate);
String total = null;
for( Row row : results2){
total = row.toString();
}
System.out.println(total);
System.out.println(total.substring(4, total.length()-1));
int totalrows = Integer.valueOf(total.substring(4, total.length()-1));
System.out.println("This is int value : "+totalrows);
XYChart.Series<String,Double> series = new XYChart.Series<>();
y.setAutoRanging(false);
y.setSide(Side.RIGHT);
if (graphUpdater == null) {
graphUpdater =new Thread(new Runnable() {
double min = 10000000;
double max = 0;
String chartData ="";
String invisible = "";
int i = 0;
XYChart.Data item;
public void run() {
while(running) {
try {
Quote quote = MulticastReciever.getInstance().getQuote(tkn.getText());
if (quote!=null) {
LocalDateTime now = LocalDateTime.now();
double value = quote.getLast();
if (value < min) {
min = value;
}
if (value > max) {
max = value;
}
i++;
a1.add(value);
if (i % 5 == 0 ){
chartData = dtf.format(now);
x.setTickLabelFill(Color.RED);
item = new XYChart.Data<>(chartData, value);
}
else {
invisible += (char)32;
chartData = dtf.format(now);
x.setTickMarkVisible(false);
item = new XYChart.Data<>(chartData, value);
}
series.getData().add(item);
lineChart.setCreateSymbols(false);
lineChart.setLegendVisible(false);
y.setLowerBound(min-(.001*min));
y.setUpperBound(max+(.001*max));
y.setTickLabelFill(Color.RED);
x.setTickMarkVisible(false);
y.setTickMarkVisible(false);
}
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
graphUpdater.start();
}
System.out.println("previousToken:"+previousToken+", GC:"+this);
int currentToken = Integer.valueOf(basic.get(tkn.getText()));
if (previousToken!=null) {
System.out.println("Going to unsubscribe token:"+previousToken);
MulticastReciever.getInstance().unsubscribeMarketData(previousToken);
}
MulticastReciever.getInstance().subscribeMarketData(tkn.getText(), currentToken);
previousToken = currentToken;
int factor=10;
if(totalrows>300){
factor =totalrows/300;
}
else
{
factor=1;
}
System.out.println(factor);
int count = 0;
x.setTickLabelRotation(45.0);
System.out.println("This is the property: "+x.isTickLabelsVisible());
x.setTickLabelGap(5000.0);
System.out.println("getTickLabelGap:"+x.getTickLabelGap());
x.setTickLabelGap(10.0);
System.out.println("getTickLabelGap:"+x.getTickLabelGap());
lineChart.getData().addAll(series);
a1.clear();
for(final XYChart.Data<String,Double> data :series.getData()){
data.getNode().addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
lbl.setText("X :"+data.getXValue()+"\nY :"+ String.valueOf(data.getYValue()));
Tooltip.install(data.getNode(), new Tooltip("X :"+data.getXValue()+"\nY :"+ String.valueOf(data.getYValue())));
}
});
}
cluster.close();
}
解决方案
推荐阅读
- reactjs - 为什么 Keyboard.dismiss 在 React Native 中不起作用?
- wix - Wix:如何在第二次安装中安装第一次安装中排除的所有功能?
- python - 如何使用 OCR 从低分辨率图像中获得更好/准确的结果
- python - 如何在 django 中验证有效的超级用户
- c++ - 为什么 std::floor(1 - std::numeric_limits
::min()) 计算结果为 1 - python - 将图像目录馈送到 TensorFlow 对象检测
- php - 需要帮助根据最旧到最新日期对数组集合进行排序 PHP/laravel
- python - Django 获取相关模型的名称无法识别 `rel` 属性
- union - 联合登录伪代码
- c# - 如何在 ASP.NET Core + Kestrel + Nginx 中使用自定义域