Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

折线被隐藏,看不到,但是数据都大于0(双Y轴折线图) #429

Open
changsir99 opened this issue Jan 10, 2025 · 2 comments

Comments

@changsir99
Copy link

b92ffb929443c97d7a36423957ffcf0

@changsir99
Copy link
Author

public static JFreeChart geneLineChart(DoubleYLineParameter parameter, Range leftRange, Range rightRange) {
//应用主题样式
ChartFactory.setChartTheme(JFreeChartUtil.geneStandardChartTheme());
// 创建JFreeChart对象
JFreeChart chart = ChartFactory.createXYStepChart(parameter.getTableName(), parameter.getXName(), "", null,
//图表方向
PlotOrientation.VERTICAL,
true, true, false);
chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
// 设置背景颜色
chart.setBackgroundPaint(ChartColor.WHITE);
LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.TOP);
// 获取绘图区域对象
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundAlpha(0.0f);
plot.setOutlinePaint(null);
plot.setRangeGridlinePaint(Color.BLACK);
// 设置x轴属性
DateAxis dateAxis = (DateAxis) plot.getDomainAxis();
dateAxis.setAutoTickUnitSelection(true);
dateAxis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd"));
dateAxis.setLowerMargin(0.01);
dateAxis.setUpperMargin(0.01);
dateAxis.setPositiveArrowVisible(true);
// 设置Y1轴
NumberAxis axis1 = new NumberAxis(parameter.getNameLeft());
axis1.setPositiveArrowVisible(true);
if (!ObjectUtils.isEmpty(leftRange)){
axis1.setRange(leftRange);
}
plot.setRangeAxis(0, axis1);
plot.setDataset(0, parameter.getDataLeft());
plot.mapDatasetToRangeAxis(0, 0);
// 设置Y2轴
NumberAxis axis2 = new NumberAxis(parameter.getNameRight());
axis2.setPositiveArrowVisible(true);
if (!ObjectUtils.isEmpty(rightRange)){
axis2.setRange(rightRange);
}
plot.setRangeAxis(1, axis2);
plot.setDataset(1, parameter.getDataRight());
plot.mapDatasetToRangeAxis(1, 1);
// 设置第一个系列的绘制器和颜色
XYSplineRenderer rendererLeft = new XYSplineRenderer(3);
rendererLeft.setSeriesPaint(0, Color.decode(parameter.getYLeftColor()));
rendererLeft.setDefaultShapesVisible(false);
plot.setRenderer(0, rendererLeft);
// 设置第二个系列的绘制器和颜色
XYSplineRenderer renderRight = new XYSplineRenderer(3);
renderRight.setSeriesPaint(0, Color.decode(parameter.getYRightColor()));
renderRight.setDefaultShapesVisible(false);
plot.setRenderer(1, renderRight);
return chart;
}This is my code, the problem hasn't been solved yet, the polyline has overflowed

@trashgod
Copy link
Contributor

See also issue #286.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants