Is it possible to make an XYChart that has its axis hidden? Ideally removed.
From looking at source it seems that it must have one due to the limitation that XYChart does not check for null Axis when layoutChartChildren() is called, which is a shame since XYChart provides for multiple data series and the addition of data in a series.
IMO a separation of concern from the Axis.
Any thoughts on a solution?
After you have shown a stage displaying the chart, call:
for (Node n: chart.lookupAll(".axis")) {
n.setVisible(false);
}
Related
I want to get the bounds (i.e. Bounds) of the XYChart plot area, which I define as the area contained within the axes of the plot (i.e. the axes form two legs of a rectangle). The ultimate purpose is to constrain a rubber band rectangle on the plot area. I started with this example and added in the constraint.
Based on the comments from James_D and kleopatra, I created a MVCE. I think the MVCE works remarkably well and compiles without warnings. More importantly, kleopatra's comment led to finding the bug when using the chart-plot-background method. The MVCE implements both methods. The chart-plot-background works for both ValueAxis and CategoryAxis. The axis method currently only works for ValueAxis.
Is using the bounds of .chart-plot-background a reliable method for determining the plot area or is using the value bounds of each axis more reliable? The axis approach definitely has more steps and more code.
Other options
I looked at the JavaFX source and plotArea looked promising but it isn't accessible.
The plotContent member is accessible via lookup(".plot-content") but groups all the data points, some of which may be outside the range set in the axes. Thus, the bounds of plotContent can be larger than the plot area bounds.
Basically I am attempting to use JFreeChart right now to graph some values. The only problem is that the values are incredibly minuscule, e.g 7.069781E-13. I believe these values are too small for JFreeChart to display. How can I display these small values visually in Java in a line chart format?
It looks like this currently:
And I want to make it look similar to this:
I found a work around.
I simply multiplied all the values by a factor of 100 so the graph now looks similar to the one in the example. I will include a disclaimer in the legend saying the chart has been multiplied by a factor to clearly see the line chart.
Also consider these alternative:
Invoke setRange(), seen here, to expand the y axis in the area of interest.
Add suitable controls, seen here, to control y zoom.
Advise users how to use the mouse for zoom control, as shown here.
Is it possible to generate a bar graph in jFreeChart where bars all start around a particular value instead of the zero axis? Our team has interest in this view.
Here is an example where the default behavior has the bars all between the value and the origin. We want the bars to be between the value and the mean (average).
I suppose a workaround is we calculate the offset from the mean and plot them in respect to the origin and then hide the axis but then we are not able to show the axis to our users.
Instead of having bar graphs stop at another value besides the origin we are just redefining the graph axis origin to be at the mean and offsetting everything. So instead of something like exposure level we now call the value axis distance from aggregate mean. Not exactly what I was originally looking in the OP but a cleaner solution overall. We'll let the user toggle between the two modes.
I'm using JFreeChart 1.0.14 in Swing application.
I have chart with multiple Y-Axis and I want to change source Axis for chart grid lines. Now them always base on one axis, even if I hide it.
I know there are few similar questions but they are old and I wonder if solution exists now.
If it doesn't what is the best workaround in this task?
For example:
http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=27885&sid=c4c609f3809d29a46e3e2bbccfac361e
There is still no way to do it natively unfortunately.
I was suggested to override XYPlot's drawRangeGridLines method, but I decided to go another way: to make it works you only need to change axis order because grid lines always depend on 0th axis (and its dataset). Make sure your axis has 0th index in plot axis collection.
NumberAxis axis = new NumberAxis(name);
plot.setRangeAxis(0, axis);
I think it's easiest way at this moment.
I've created a XYChart with numerical values different (for example temperatue with pressure) so I want to draw my own axeS just beside my chart. To do the following I've to unshow the YAxis, how should I do that ?
By using a trick: The Chart needs the Y Axis to remain in place so it knows where to render your content. You can, however, hide it. Hide the tick labels and set the axis' opacity to 0 using this code:
chart.getYAxis().setTickLabelsVisible(false);
chart.getYAxis().setOpacity(0);
The axis will still be there, but not shown.
I found that if I hid the chart using the following code:
chart.getXAxis().setTickLabelsVisible(false);
chart.getXAxis().setTickMarkVisible(false);
((Path)chart.getXAxis().lookup(".axis-minor-tick-mark")).setVisible(false);
Then I get about ~10 pixels less blank space on the bottom. IF the space was an issue for your application then you could use css offsets to correct it. This solution may have more predictable offsets.
SOLVED: I got this to work for sharing a common x-axis for two charts stacked vertically:
Create two charts, each with their own identical copy of the x-axis object, setting identical upper and lower bounds (optionally by binding).
Then hide the x-axis in the second chart like this:
chart = new LineChart<Number,Number>(xaxis2,yaxis2) {
{// hide xAxis in constructor, since not public
getChartChildren().remove(getXAxis());
// not getPlotChildren()
}
};
You'll want to set the widths of your y-axes to be the identical, e.g.
int w = 60;
yaxis.setMaxWidth(w);
yaxis.setMinWidth(w);
yaxis.setPrefWidth(w);
yaxis2.setMaxWidth(w);
yaxis2.setMinWidth(w);
yaxis2.setPrefWidth(w);