How to get rid of axis lines in a linechart with CSS? - css

In JavaFX, I have added a border to a LineChart with the following CSS:
.chart-plot-background
{
-fx-border-color: black;
-fx-border-width: 4px;
-fx-border-insets: -2px;
}
And the chart looks like:
I cannot, however, figure out how to get rid of the blue "axis" lines in the middle of the border lines. What do I need to do to either make these x and y axis lines either black or invisible?

It is a a little difficult to know exactly what you wish to achieve. But a general outline is below. Hopefully it gives you further direction on how you can modify this kind of stuff yourself and you will be able to modify it to get exactly the effect you need.
Background
Examine the modena.css file which you can find inside the jfxrt.jar file that ships with your Oracle JDK 8 installation. This file defines the styles for charts. You can override these styles as needed inside a custom CSS stylesheet that you supply.
The default value for the top border color for instance is defined as:
.axis:top {
-fx-border-color: transparent transparent AXIS_COLOR transparent;
}
Controlling Chart Style via CSS
To turn off plotting the axis lines on the chart you can set the appropriate values of the axis border colors to transparent (or null). For example:
.axis:top {
-fx-border-color: transparent;
}
Additionally, your sample chart features grid lines, which will be drawn over the top of the custom chart-plot-background border that you are defining. To prevent that occurring, you can also make the grid lines transparent. In the sample I also commented out the -fx-border-insets: -2px value as that places your border underneath the ticks on the axis, which looks weird.
Sample CSS
So in summary a sample CSS file is similar to below. The chart plot is based upon Oracle sample line chart code.
.chart-plot-background {
-fx-border-color: black;
-fx-border-width: 4px;
/*-fx-border-insets: -2px;*/
}
.axis:top {
-fx-border-color: transparent;
}
.axis:right {
-fx-border-color: transparent;
}
.axis:bottom {
-fx-border-color: transparent;
}
.axis:left {
-fx-border-color: transparent;
}
.chart-vertical-grid-lines {
-fx-stroke: transparent;
}
.chart-horizontal-grid-lines {
-fx-stroke: transparent;
}
When plotted, with the above CSS, a sample chart looks like this:

Related

How to remove a line of shadow under javafx button

Using JavaFX 15
There's a line of shadow below the border of the JavaFX FXML button.
is it possible to make it transparent using CSS? As I do not know which attribute it belongs to.
Picture of the button attached below
.btn{
-fx-background-color: black;
-fx-background-radius: 30px;
-fx-border-color: white;
-fx-border-radius: 30px;
-fx-border-width: 3px;
}
colored with black background and white borderline for visibility
It is possible that what you are seeing is the background spilling out past the border. Since you have customized the border thickness in the CSS, you may also need to adjust background insets.
See the CSS docs for Region https://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#region
I have never seen this behaviour, but a nice reference for attributes available to the basic JavaFX-classes can be found here: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html
This could maybe be due to not overwriting all the standard JavaFX button style attributes.

Controlsfx PopOver style and focus

I'm working with a Popover, which is used as a tooltip-like help-display for a Textfield.
It contains a Label and a TextArea as content and is created, when the user enters the text field. (Via FocusPropery.addListener )
I apply the style using:
popOver.getRoot().getStylesheets().add(...)
(as found in the documentation documentation )
This works for the TextArea, but only partialy for the label.
My Style looks like this:
*{
-tb-dark-grey: rgb(32,38,44);
}
.root {
-fx-base: -tb-dark-grey;
-fx-background: -tb-dark-grey;
-fx-control-inner-background: -tb-dark-grey;
}
This works very good in my main window. Including all Labels and TextAreas. Everything gets a dark-blue background with white text.
For the Label in the Popover however it changes only the text color to white but the background stays at the usual light grey.
I tried using the TextArea as a workaround. This works for the style. But it always steals the focus from the text field. This makes it impossible to type something. Disabling the TextArea works,but that changes the style of the TextArea.
I already tried appling the style as found in this other question.
I also tried getting the focus back with, which also did not work.
popup.Show(this.inputField)
this.inputField.requestFocus(); // also tried this with Platform.runLater
Your problem should be that Label doesn't use any of the colors you have overwritten in your .root style class. According to JavaFX CSS reference guide you can style the background of a Label by using fx-background-color.
Adding the following line to your stylesheet should do the trick:
.label {
-fx-background-color: -tb-dark-grey;
}
You can also apply the style individually for each label by creating a custom style class if you want to style labels differently:
CSS:
.custom-label {
-fx-background-color: -tb-dark-grey;
}
And then applying it to a specific label:
Label label = new Label("I am a label");
label.getStyleClass().add("custom-label");
Edit: You should probably be aware that your TextArea will not display the exact color you've defined in your stylesheet. If you check the Modena stylesheet, which is the default theme and style for JavaFX (how to find it is described here). You will find the following css for the TextArea content:
.text-area .content {
/*the is 1px less top and bottom than TextInput because of scrollpane border */
-fx-padding: 0.25em 0.583em 0.25em 0.583em; /* 3 7 3 7 */
-fx-cursor: text;
-fx-background-color:
linear-gradient(from 0px 0px to 0px 4px, derive(-fx-control-inner-background, -8%), -fx-control-inner-background);
-fx-background-radius: 2;
}
As you can see. The background color of the TextArea content is not exactly the -fx-control-inner-background that you have defined in your stylesheet, but a linear gradient that goes from a color derived from -fx-control-inner-background to the color you want. This might not even be noticeable for you, but could be good to know.
Setting the color of the TextArea background so that is it precisely your color could be done like this:
.text-area .content {
-fx-background-color: tb-dark-grey;
}

-fx-border-style doesn't look as expected on runtime but on SceneBuilder

The following style looks as expected on SceneBuilder. (The only visible border is the bottom one and it is dotted.)
But it looks different on runtime. (All borders are visible and solid.)
.floatingPanel-title{
-fx-text-alignment: center;
-fx-text-fill: CORNFLOWERBLUE;
-fx-font-weight: bold;
-fx-font-size: 15px;
-fx-background-color: #545050;
-fx-border-style: none none dotted none;
-fx-border-color: white;
}
I tried some by swaping the lines or commenting-out some parts but the problem is still an issue.
What do you suggest as a solution?
Note:
1) I applied this style to a label and also a panel. The problem is valid for both.
2) I have already tried clean-compile. Problem still exists.
It seems to be a bug, sorry. On my testing with JavaFX 8u40:
1) Even though the official JavaFX CSS Reference Guide says on -fx-border-style as
A series of border style values, separated by commas. Each item in the
series applies to the corresponding item in the series of border
colors.
The comma separated example behaves weird and wrongly than not comma separated one. i.e. these
-fx-border-style: dotted dashed dashed dashed;
-fx-border-color: red red red red;
-fx-border-width: 2;
and
-fx-border-style: dotted , dashed , dashed , dashed;
-fx-border-color: red red red red;
-fx-border-width: 2;
renders differently. Not using commas seems more accurate despite the doc.
2) The border style option none is not working in JavaFX 8 but in JavaFX 2. Instead of this you may choose to use hidden.
-fx-border-style: hidden hidden dotted hidden;
3) The different rendering of SceneBuilder and at runtime may be caused by usage of different versions of JavaFX. You can inspect the used version by
System.out.println(com.sun.javafx.runtime.VersionInfo.getRuntimeVersion());
Finally, after observation of yourself, you are welcome to file a jira issue or vote for existing one.

How to set border color in Line Chart

I have a LineChart graph. I want to color rectangular border of graph area.
"-fx-border-color: black transparent transparent transparent;" add border to x-axis or y-axis.
"-fx-border-color: black" add border around complete chart.
But i need border around graph area only as shown in attachment
Any help would be useful.
Thanks
Border CSS
.chart-plot-background {
-fx-border-color: red;
-fx-border-style: solid;
-fx-border-width: 4px;
-fx-border-insets: -2px;
}
Gives you this:
The green border around the chart plot content is what the CSS above provides.
On dotted lines
You will notice there are dashed lines and axes drawn on top of the green border. Perhaps you want the border behind those lines, perhaps you want it on top, perhaps you don't want to draw those dotted lines at all.
If it is fine to have the border behind the dotted lines you don't need to do anything else.
If you don't want to draw the dotted lines, you can remove them:
lineChart.setAlternativeRowFillVisible(false);
lineChart.setAlternativeColumnFillVisible(false);
lineChart.setHorizontalGridLinesVisible(false);
lineChart.setVerticalGridLinesVisible(false);
and adjust the insets of your bounding rectangle accordingly:
.chart-plot-background {
-fx-border-color: forestgreen;
-fx-border-style: solid;
-fx-border-width: 4px;
-fx-border-insets: 0 0 0 1;
}
If you want to keep the dotted lines and draw your rectangle on top of the chart, then you can place the chart in a StackPane, run chart.lookup(".chart-plot-background") after the chart has been displayed, monitor the bounds of the resultant chart background node and add a new rectangle to the top of the stack which is bound to the chart background bounds, like in this layout bounds demo. You probably don't want to do that though.
How to do this stuff yourself
Using tools like ScenicView or the css analyzer in SceneBuilder, or studying the CSS reference guide or the modena.css file in the jfxrt.jar shipped with your JRE can help you determine the CSS rules you need.
you can test that in your css file :
/* chart background */
.chart-plot-background {
-fx-background-color: blue;
}
/* frame background */
.chart{
-fx-background-color: pink;
}
/* border content */
.chart-content{
-fx-padding: 0px;
-fx-border-color: black;
-fx-border-width: 3px;
}

How can the css dottled border be implemented?

I want to use GWT Canvas to draw a dashed border around a canvas element like Rectangle.
I like the style that the css attribute border: dashed produces, especially the way the corners are displayed, like seen here: https://developer.mozilla.org/en-US/docs/CSS/border-style
Can the "source" code of how this dashed line is produces be inspected somewhere?
Found this function in the Firefox source: nsCSSRenderingBorders. I don't understand the code, but the answer probably lies in there.
http://mxr.mozilla.org/mozilla-central/source/layout/base/nsCSSRenderingBorders.cpp
If you want that styling for your borders :
element.style {
background-color: palegreen;
border-style: dashed;
}
or
element.style {
border-style: 2px dashed #000;
}
Is this what you want ?
If you want a java function to do so, or some place to start to 'study' go here gwtcanvasdemo. and there is a link to the sources. Also, another post on SO related to the subject dotted stroke in canvas and then, there is /DashedLineRenderer.java

Resources