Javafx Jfreechart fx:如何在组合域绘图中调整子绘图的大小
我正在尝试为char面板中的组合域绘图实现“子绘图高度调整按钮”。Javafx Jfreechart fx:如何在组合域绘图中调整子绘图的大小,javafx,jfreechart,combinedchart,jfreechart-fx,Javafx,Jfreechart,Combinedchart,Jfreechart Fx,我正在尝试为char面板中的组合域绘图实现“子绘图高度调整按钮”。 我有一个这样的控制器: package org.my.jfxtestplots; import java.io.IOException; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.util.Date; import java
我有一个这样的控制器:
package org.my.jfxtestplots;
import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.Random;
import javafx.application.Platform;
import javafx.embed.swing.SwingNode;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.annotations.XYTitleAnnotation;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.block.BlockBorder;
import org.jfree.chart.plot.CombinedDomainXYPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.ui.RectangleAnchor;
import org.jfree.chart.ui.RectangleEdge;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.time.TimeSeriesDataItem;
public class myController {
private CombinedDomainXYPlot plot_combinato;
private ChartPanel chart_panel_preview;
private int wgt=1;
@FXML
private Button btnPlot;
@FXML
private ScrollPane scroll_waves;
@FXML
private Button btnPlotBigger;
@FXML
private void btnPlot_click(ActionEvent event) {
NumberAxis rangeAxis1;
rangeAxis1 = new NumberAxis();
String panel_title = "Titolo";
ZoneId zoneId = ZoneId.systemDefault();
int wCounter=0;
TimeSeries series;
TimeSeriesCollection dataset;
LocalDateTime dateStart;
LocalDateTime new_date;
long timestamp;
float time_sample_value;
long current_time;
Millisecond ms;
TimeSeriesDataItem item;
float numero;
LegendTitle legend_title;
XYPlot subplot;
XYItemRenderer renderer;
//
Random rand =new Random();
int upper_bound = 10000;
SwingNode chart_panel_preview_container_swingNode;
scroll_waves.setFitToWidth(true);
scroll_waves.setFitToHeight(false);
//
plot_combinato = new CombinedDomainXYPlot(new DateAxis("Time"));
plot_combinato.setOrientation(PlotOrientation.VERTICAL);
plot_combinato.setRangeAxis(rangeAxis1);
chart_panel_preview = new ChartPanel(new JFreeChart(panel_title,
JFreeChart.DEFAULT_TITLE_FONT,
plot_combinato,
true));
//
for (int idStation=0; idStation < 10; idStation++) {
wCounter+=1;
series = new TimeSeries("STAZ" + String.valueOf(wCounter) + " CHAN");
dateStart = LocalDateTime.now();
timestamp = dateStart.atZone(zoneId).toInstant().toEpochMilli();
for (Integer i =0; i< 1000; i++) {
time_sample_value = i.floatValue()/(float)100.0; //tmpWave.getSamplingRate(); //the time value of the sample
current_time= timestamp + Float.valueOf(time_sample_value*1000).intValue();
new_date = millsToLocalDateTime(current_time);
ms= new Millisecond(Date.from(new_date.atZone(zoneId).toInstant()));
numero = rand.nextFloat();
item = new TimeSeriesDataItem(ms, numero);
series.add(item);
}
//
dataset = new TimeSeriesCollection();
dataset.addSeries(series);
//
rangeAxis1 = new NumberAxis();
rangeAxis1.setAutoRange(true);
renderer = new StandardXYItemRenderer();
renderer.setSeriesPaint(0, new java.awt.Color(70,240,8)); // Colore del segnale
//
subplot = new XYPlot(dataset, null, rangeAxis1, renderer);
subplot.setBackgroundPaint(new java.awt.Color(68,68,68)); // Colore dello sfondo
// Mostra le linee crosshair per pickare tempo-ampiezza
subplot.setDomainCrosshairVisible(false);
subplot.setRangeCrosshairVisible(false);
//
legend_title = new LegendTitle(subplot);
legend_title.setItemFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 9));
legend_title.setBackgroundPaint(new java.awt.Color(200, 200, 255, 100));
legend_title.setItemPaint(java.awt.Color.WHITE);
legend_title.setFrame(new BlockBorder(java.awt.Color.GRAY));
legend_title.setPosition(RectangleEdge.BOTTOM);
XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, legend_title,RectangleAnchor.BOTTOM_RIGHT);
//
ta.setMaxWidth(0.48);
subplot.addAnnotation(ta);
////
//subplot.setWeight(1);
plot_combinato.add(subplot, wgt); //, 1000 + wCounter+1);
System.out.println("PESO: " + subplot.getWeight());
}
chart_panel_preview_container_swingNode= new SwingNode();
this.createSwingContent(chart_panel_preview_container_swingNode, chart_panel_preview);
scroll_waves.setContent(chart_panel_preview_container_swingNode);
}
//--------------------------------------------------------------------------------
public static LocalDateTime millsToLocalDateTime(long millis) {
Instant instant = Instant.ofEpochMilli(millis);
LocalDateTime date = instant.atZone(ZoneOffset.UTC).toLocalDateTime();
return date;
}
//--------------------------------------------------------------------------------
private void createSwingContent(SwingNode swingNode, JComponent t) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Platform.setImplicitExit(true);
swingNode.setContent(t);
}
});
}
//--------------------------------------------------------------------------------
@FXML
private void btnPlotBigger_click(ActionEvent event) {
wgt+=1;
btnPlot.fire();
}
}
package org.my.jfxtestplots;
导入java.io.IOException;
导入java.time.Instant;
导入java.time.LocalDateTime;
导入java.time.ZoneId;
导入java.time.ZoneOffset;
导入java.util.Date;
导入java.util.Random;
导入javafx.application.Platform;
导入javafx.embed.swing.SwingNode;
导入javafx.event.ActionEvent;
导入javafx.fxml.fxml;
导入javafx.scene.control.Button;
导入javafx.scene.control.ScrollPane;
导入javax.swing.JComponent;
导入javax.swing.SwingUtilities;
导入org.jfree.chart.ChartPanel;
导入org.jfree.chart.JFreeChart;
导入org.jfree.chart.annotations.xytileanotation;
导入org.jfree.chart.axis.DateAxis;
导入org.jfree.chart.axis.NumberAxis;
导入org.jfree.chart.block.BlockBorder;
导入org.jfree.chart.plot.CombinedDomainXYPlot;
导入org.jfree.chart.plot.PlotOrientation;
导入org.jfree.chart.plot.XYPlot;
导入org.jfree.chart.renderer.xy.StandardXYItemRenderer;
导入org.jfree.chart.renderer.xy.XYItemRenderer;
导入org.jfree.chart.title.LegendTitle;
导入org.jfree.chart.ui.RectangleAnchor;
导入org.jfree.chart.ui.RectangleEdge;
导入org.jfree.data.time.毫秒;
导入org.jfree.data.time.TimeSeries;
导入org.jfree.data.time.TimeSeriesCollection;
导入org.jfree.data.time.TimeSeriesDataItem;
公共类myController{
专用组合图组合图;
私有图表面板图表面板预览;
私有整数wgt=1;
@FXML
私人按钮btnPlot;
@FXML
私人滚动窗格滚动波;
@FXML
私人按钮BTNPlotbiger;
@FXML
私有无效btnPlot\u单击(ActionEvent事件){
数轴范围轴1;
rangeAxis1=新的NumberAxis();
字符串面板\u title=“Titolo”;
ZoneId ZoneId=ZoneId.systemDefault();
int wCounter=0;
时间序列;
时间经验收集数据集;
LocalDateTime日期开始;
LocalDateTime新日期;
长时间戳;
浮动时间样本值;
长电流时间;
毫秒ms;
TimeSeriesDataItem项;
浮点数;
传奇人物(传奇人物);;
XYPlot子地块;
XYItemRenderer渲染器;
//
Random rand=新的Random();
int上界=10000;
SwingNode图表\面板\预览\容器\ SwingNode;
滚动_waves.setFitToWidth(true);
滚动_waves.setFitToHeight(false);
//
plot_combinato=新的组合DomainxyPlot(新的日期轴(“时间”));
绘图组合设置方向(绘图方向垂直);
plot_combinato.setRangeAxis(rangeAxis1);
图表面板预览=新建图表面板(新建JFreeChart)(面板标题,
JFreeChart.DEFAULT\u TITLE\u字体,
联合地块,
是的);
//
对于(int-idStation=0;idStation<10;idStation++){
wCounter+=1;
series=新的时间序列(“STAZ”+String.valueOf(wCounter)+“CHAN”);
dateStart=LocalDateTime.now();
timestamp=dateStart.atZone(zoneId.toInstant().toEpochMilli();
对于(整数i=0;i<1000;i++){
time_sample_value=i.floatValue()/(float)100.0;//tmpWave.getSamplingRate();//样本的时间值
当前_时间=时间戳+浮点.valueOf(time_sample_value*1000).intValue();
新建日期=millsToLocalDateTime(当前时间);
ms=新的毫秒(Date.from(new_Date.atZone(zoneId.toInstant());
numero=rand.nextFloat();
项目=新的TimeSeriesDaitem(毫秒,数字);
系列。添加(项目);
}
//
dataset=新的TimeSeriesCollection();
dataset.addSeries(系列);
//
rangeAxis1=新的NumberAxis();
rangeAxis1.setAutoRange(真);
renderer=新的StandardXYItemRenderer();
renderer.setSeriesPaint(0,新java.awt.Color(70240,8));//Colore del segnale
//
子绘图=新的XYPlot(数据集、null、rangeAxis1、渲染器);
subplot.setBackgroundPaint(新java.awt.Color(68,68,68));//Colore dello sfondo
//根据pickare tempo ampiezza设计的Mostra le linee十字准线
子地块setDomainCrosshairVisible(false);
子批次SetRangeCroshairVisible(假);
//
legend_title=新LegendTitle(子地块);
图例_title.setItemFont(新java.awt.Font(“Dialog”,java.awt.Font.BOLD,9));
图例_title.setBackgroundPaint(新java.awt.Color(200200255100));
图例_title.setItemPaint(java.awt.Color.WHITE);
图例_title.setFrame(新的块边框(java.awt.Color.GRAY));
图例\标题.设置位置(矩形边缘.底部);
XYTitleAnnotation ta=新的XYTitleAnnotation(0.98,0.02,图例标题,矩形锚。右下角);
//
ta.设置最大宽度(0.48);
子批次添加注释(ta);
////
//小批整重(1);
添加(子地块,wgt);/,1000+W计数器+1);
System.out.println(“比索:+subplot.getWeight());
}
图表\面板\预览\容器\ swingNode=新swingNode();
这个.createSwingContent(图表\u面板\u预览\u容器\u swingNode,图表\u面板\u预览);
滚动\u waves.setContent(图表\u面板\u预览\u容器\u swingNode);
}
myChartViewer.setPrefHeight(..,..)