Set "auto" Range for an XYAreaChart - java

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.

Related

Using different x-axis labels for n lines in a graph

So I am using MPAndroidChart as library for the viewing of graphs in my app. Now I wanted to make a LineGraph with several lines (n). The problem is that those lines do not have the same x-axis labels and I have not found a solution to put the x-axis labels in relation to the entries. Furthermore does the new line start at x-value 0. Therefore my lines do not fill the entire diagram area. Because when I have two lines with 6 entries each, the x-axis labels have the size 12. And therefore the lines end at half of the diagram.
How do I solve that?
Example LineGraph
I assume you mean the library available here: https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java
From the code I grasped, LineChart does not support dual x-axis (while it support dual y-axis, left and right). See here , XAxis.java and YAxis.java
On the other hand, looks like the x-axis fits the data range automatically (there is no method to set min/max of x-axis).
An example of the graph >>
I would suggest you to re-organize your chart to switch x and y axis, and use two y axis if your series have different range of y values, but you want to show them in a chart. Double y-axis is more common than double x-axis from my experience, and easier to understand as well.

JFreechart set String value and/or Symbol to Xaxis

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.

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

setting up the same length of ValueAxis with jfreechart

I am plotting several jfree charts in one window and want to align all chart.
All graph have the same range for x-axis and y-axis is displaying in the left.
However, when I am trying to set up fixed length for valuesAxis ,each graph still having different length of valueAxis.
There is extract of my code;
ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setFixedDimension(40);
rangeAxis.setFixedAutoRange(40);
For time being I solved it by not displaying it at all
rangeAxis.setVisible(false);
Is these same way to set up the same length for all charts?
Consider using either a CombinedDomainXYPlot or a CombinedRangeXYPlot to display your data; both will ensure the data area is the same size for all their subplots (AFAIK).

Categories

Resources