![](/img/trans.png)
[英]how to set range of x-axis with timestamp for xylinechart in javaFX?
[英]How to set logarithmic scale for domain and range axis in XYLineChart
有沒有辦法為 x 軸和 y 軸設置對數刻度。
我在下面添加了用於創建圖表的代碼以供參考。
XyLineChartBuilder lineBuilder = DynamicReports.cht.xyLineChart()
.setTitle(reportSection.getGraphName())
.setTitleFont(boldFont)
.setXValue(xColumn)
.series(yAxisLineSeries)
.setXAxisFormat(DynamicReports.cht.axisFormat()
.setLabel(reportSection.getxAxisCaption()))
.setYAxisFormat(DynamicReports.cht.axisFormat()
.setLabel(reportSection.getyAxisCaption()))
.setDataSource(createDataSource(reportSection, noOfYaxis));
我嘗試使用基數 10 和基數 2,但兩者都沒有繪制負值。
LogarithmicAxis
提供了一個setAllowNegativesFlag()
方法,該方法可以設置為“ true
以允許數據中的負值”,或“ false
以能夠繪制任意接近零的正值”。 我已經修改了這個例子來說明效果。
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.LogarithmicAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
/**
* @See https://stackoverflow.com/a/53912014/230513
* @see https://stackoverflow.com/a/22450677/230513
* @see https://stackoverflow.com/a/10353270/230513
*/
public class Test {
private static final int N = 10;
private void display() {
XYSeries series = new XYSeries("Series");
for (int i = -N; i <= N; i++) {
series.add(i, i);
}
LogarithmicAxis xAxis = new LogarithmicAxis("X");
xAxis.setAllowNegativesFlag(true);
LogarithmicAxis yAxis = new LogarithmicAxis("Y");
yAxis.setAllowNegativesFlag(true);
XYPlot plot = new XYPlot(new XYSeriesCollection(series),
xAxis, yAxis, new XYLineAndShapeRenderer(true, false));
JFreeChart chart = new JFreeChart(
"Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
JFrame f = new JFrame("Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new ChartPanel(chart) {
@Override
public Dimension getPreferredSize() {
return new Dimension(700, 400);
}
});
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new Test().display();
}
});
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.