JFreechart set String value and/or Symbol to Xaxis - java

I have a chart whose data are obtained from the database and the client now needs to be symbols printed below the X axis in the curve peaks.
I tried something like NumberAxis.createIntegerTickUnits() method, but to no avail.
How do I replace the values of the X axis by the symbols?
The needed chart is this:

Depending on the desired effect,
Consider using a SymbolAxis, illustrated here on the range axis.
Consider using an XYItemLabelGenerator, illustrated here.

Related

How can I graph values that are incredibly small in Java?

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.

Remove an axis from JavaFX Chart

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);

Setting the minimum value of yAxes in afreechart android

I am using afreechart to plot a timeseries as in this example code
However if the chart is panned vertically you reach the areas of the negative y axes. I want to avoid that and would want to set the min and max for both y and x axes.
I tried doing something like the below:-
ValueAxis yaxes=plot.getRangeAaxis();
yaxes.setRange(0,100);
But this does not seem to work and I am still able to pan the chart into non-negative y values area.
Ok I solved it myself.. I was extending from the class DemoView as in the example. I just changed some values as below:-
this.domainMovable=true;
this.rangeMovable=false;
It might be a dirty way but does my job

Set "auto" Range for an XYAreaChart

I'm using the JFreechat API to draw an XYAreaChart with a TimeSeriesCollection dataset. The values I'm putting in the dataset are variables with no limit: they can go from 0 to more than 1000. The problem here is that I want to make the ValueAxis automatically fit the data.
I have tried to use :
XYPlot plot = mychart.getXYPlot();
ValueAxis axis = plot.getDomainAxis();
axis.setAutoRange(true);
I see that with setAutoRange, it is not so "automatically." It's true that it changes the axis when the plot gets big values, but it doesn't re-size the axis when there is no more big data as shown here:
I want that the axis Range gets back to fit the biggest value shown (~400 in this example) because it becomes hard to read the little values with this range without using zoom.
Is that possible?
I'd examine two approaches:
A dataset that discards old data such as DynamicTimeSeriesCollection, shown here.
A dataset whose series allow a maximum age such as TimeSeriesCollection, shown here.

JFreeChart Crosshair on a combined plot

I'm using a combined plot composed of 2 graph which share the same X axis (by sharing, I mean, the timeframe is the same for the two graph). The upper graph is a regular timeseries while the lower chart is a barchart. I would like to display a crosshair on the combined chart as a whole... Right now I can display crosshair only on each graph separately even thought I have specify on the combined plot that I wanted to display the crosshair. To be more explicit, I can't synchronise both crosshair... Any idea on how to achieve that ?
thanks
It would appear to work if you use a shared domain axis, as discussed here and as shown in CrosshairDemo2? In addition, an sscce might help clarify your usage.

Categories

Resources