Just take a look at this image:
I have 60 entries on the X-axis, the labels of the values do not fit in the small space so they are shown as "...". Is there a way to somehow hide some of these labels in a way that the entire label of the remaining values are shown?
You can override the tick units used by the axis by use the axis' setTickunit() method.
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/axis/NumberAxis.html#setTickUnit-org.jfree.chart.axis.NumberTickUnit-
Related
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.
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);
The left three lines of data: 0.9,2450,0.4867 in the Y-axis is shown in proportion.
Right three lines (the other two data is too small to show up), how to do the left?
I see several alternatives:
Condition your data to show relative change, as is done in the chart on the left.
Add a second axis to show the larger dynamic range, as is done in DualAxisDemo2.
Enable the zoom feature in ChartPanel, as suggested in this example.
I was unable to find a way to display the labels (the corresponding values of y axis) vertically. By default it displays horizontally but if values are big it gets overlapped.
Please I am not looking to vertically display the labels of domain axis (x axis) but to display corresponding y values as a label on top of bar horizontally.
BarChartDemo7 among the demos is an example.
Crowding can be a problem, but changing ItemLabelPosition or the ItemLabelAnchor may not solve the problem. As an alternative, consider using a tooltip generator, discussed here. For more complex rendering needs, add a ChartMouseListener, mentioned here, and update an adjacent component with the details.
My JSlider first value is 0 and the last value is 8850. I want to set the major tick spacing so that the last value (8850) to be printed. For example if I set the major tick spacing to 550 the last value printed will be 8800.
You can use the JSlider#setLabelTable method to control which labels are painted. The JSlider#createStandardLabels avoids that you have to manually create all labels. It is sufficient to use that method to generate them for you, and just add your label for the max value to it.
The Swing slider tutorial even has sample code how to use custom labels