I'm using an XYPlot in JFreeChart. All the lines on it are XYSeries objects. Both axes are NumberAxis objects. The Y-Axis range is from 0-1, with ticks every .1. Along with displaying the numbers though, I'd like to display text on the Y-Axis, like High/Medium/Low. High would cover .7-1, etc. What is the best way to go about doing this?
I have some JFreeChart experience, and after a little research I don't have an answer for adding the three labels to the axis.
However, as an alternative approach, you should be able to delineate these three areas on the plot with colors by setting a MarkerAxisBand for the NumberAxis (using this method).
You could then add interval markers to the MarkerAxisBand to highlight the three areas.
try this ... it can give similare result
JFreeChart Text Annotations not Working?
XYTextAnnotation textAnnotaion = new XYTextAnnotation(description, xMid, yMid);
plot.addAnnotation(textAnnotaion);
textAnnotaion.setRotationAngle(90.0);
Related
I need a chart with multiple lines, and each of this line needs to have its own YAxis so it could scale to the full size of rgaph view. I know how to implement this with MP Chart if I have two data sets. But I need draw on graph up to 16 different data sets with its own YAxises. Any suggestion with code example please?
I need to create a scatter plot in Java, which shows a label in a point position. For example, I have a plot with a point in position (10,20), I need to show a string in that position of the plot instead of a colored point. Is this possible using some library? I have been trying with JChart2D, JFreeChart without success, I just get normal scatter plots.
Thanks for your time.
I know how to create a CategoryPlot and then set the DomainAxis labels to use two lines. This is the idea:
CategoryAxis categoryAxis = categoryPlot.getDomainAxis();
categoryAxis.setMaximumCategoryLabelLines(2); // Mmmm... nice labels
But I'm having trouble doing "the same thing" for a Timeseries chart. The problem is that the DateAxis is a ValueAxis rather than a CategoryAxis. That makes sense because the dates are values. But I don't like the look of the chart when it uses only a single line for the date. You can see a sample chart in my answer in this thread. I want to format my dates to use 2 lines. But I cannot do it like this:
DateAxis dateAxis = (DateAxis)xyPlot.getDomainAxis();
dateAxis.setMaximumCategoryLabelLines(2); // method does not exist
How can I get those Date labels onto 2 lines?
Using setVerticalTickLabels(), shown here, may alleviate the horizontal crowding; using setDateFormatOverride() may mitigate the resulting vertical space cost.
I have an XYLineChart, where the labels on the X axis are written horizontally. I would like to be able to write them vertically (descending).
I can already do this for BarCharts:
CategoryPlot plot = (CategoryPlot) chart.getPlot();
final CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
but an XYChart returns an XYPlot, rather than a CategoryPlot, and the getDomainAxis() of an XYPlot returns a ValueAxis, not a CategoryAxis. ValueAxis lets me call
setVerticalTickLabels(true);
which is almost there! But it draws them ascending, rather than descending. Any way around this?
Thanks,
Edit: I need the domain axis to stay at the bottom of the chart. Hadn't considered it being any other way when making the original post.
ValueAxis does this automatically in drawTickMarksAndLabels() for an axis on the RectangleEdge.TOP edge:
xyPlot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT);
Example based on a variation of ScatterAdd.
Answering my own question, this didn't seem to be possible, so I had to add the functionality to the jfreechart source myself.
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).