java - Line chart symbols clipped by axis when they lie on the axis -
i have line chart defined axis range, , plotting points part of line lie on axis. default points , line segments lie on axis clipped, shown in below screen shot;
my code below;
package com.jtech; import javafx.application.application; import javafx.event.eventhandler; import javafx.scene.node; import javafx.scene.scene; import javafx.scene.chart.axis; import javafx.scene.chart.linechart; import javafx.scene.chart.numberaxis; import javafx.scene.chart.xychart; import javafx.scene.input.mouseevent; import javafx.stage.stage; public class showsymbol extends application { @override public void start(stage stage) { final numberaxis xaxis = new numberaxis(0,4,1); final numberaxis yaxis = new numberaxis(0,10,2); final linechart<number, number> linechart = new linechart<>(xaxis, yaxis); xychart.series series = new xychart.series(); final xychart.data d1 = new xychart.data(0.0, 0.0); final xychart.data d2 = new xychart.data(0.5, 2.0); final xychart.data d3 = new xychart.data(1.0, 2.5); final xychart.data d4 = new xychart.data(1.5, 3.5); final xychart.data d5 = new xychart.data(2.0, 10.0); final xychart.data d6 = new xychart.data(2.5, 10.0); final xychart.data d7 = new xychart.data(3.0, 0.0); final xychart.data d8 = new xychart.data(3.5, 0.0); final xychart.data d9 = new xychart.data(4.0, 8.0); series.getdata().addall(d1,d2,d3,d4,d5,d6,d7,d8,d9); linechart.getdata().add(series); linechart.setlegendvisible(false); final scene scene = new scene(linechart, 400, 300); scene.getstylesheets().add(getclass().getresource("/css/show.css").toexternalform()); stage.setscene(scene); stage.show(); } public static void main(string[] args) { launch(args); } }
where style sheet contains;
.chart-series-line { -fx-stroke: grey; -fx-stroke-width: 4.0px; -fx-effect: null; } .chart-line-symbol { -fx-background-color: #860061, white; -fx-background-insets: 0, 2; -fx-background-radius: 0; -fx-padding: 4px; }
i keep axis range specified (0->4 , 0->10), show complete segments of symbols , lines lie on them. possible?
the problem facing plot area clipped. code excerpt xychart.java:
private final group plotarea = new group(){ @override public void requestlayout() {} // suppress layout requests }; private final group plotcontent = new group(); private final rectangle plotareaclip = new rectangle(); public xychart(axis<x> xaxis, axis<y> yaxis) { ... getchartchildren().addall(plotbackground,plotarea,xaxis,yaxis); ... plotarea.setclip(plotareaclip); ... }
a solution might disable clip. give other troubles (line overlapping, etc). nontheless, since there no proper api this, here's quick & dirty way how disable clipping:
region chartcontent = (region) linechart.lookup(".chart-content"); for( node node: chartcontent.getchildrenunmodifiable()) { if( node instanceof group) { group plotarea= (group) node; plotarea.setclip(null); } }
it'll then:
bottom line: you're better off implementing own chart (e. g. use , change source of linechart , xychart) supports feature. or file change request proper solution.
Comments
Post a Comment