Any ideas? There is no setRadiusLabelsVisible(...) or setLabelGenerator(null) method which exists for at least some of the other charts. :)
It looks like a PolarPlot has a radial Axis, so
PolarPlot plot = (PolarPlot) chart.getPlot();
ValueAxis axis = plot.getAxis();
axis.setTickLabelsVisible(false);
Related
I've trying to find a solution to this problem.
I have an XYLineChart and I would like to have uneven spaces between tick units.
This is my code:
//Method (receive the dataset and return the chart)
private JFreeChart createChart(XYDataset dataset){
//--------create XYlineChart
JFreeChart oChart = ChartFactory.createXYLineChart("XYLineChart", "X", "Y", dataset);
XYPlot plot = (XYPlot) oChart.getPlot();
plot.setOrientation(PlotOrientation.VERTICAL);
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
plot.setBackgroundPaint(Color.WHITE);
plot.setDomainGridlinesVisible(true);
plot.setDomainGridlinePaint(Color.black);
plot.setRangeGridlinePaint(Color.black);
// render shapes and lines
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
plot.setRenderer(renderer);
renderer.setBaseShapesVisible(true);
renderer.setBaseShapesFilled(true);
NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
xAxis.setNumberFormatOverride(THOUSANDS); //Override and Use a my NumberFormat
xAxis.setRange(0, 8000);
//I want to use this with my own set of tickUnits, the values(x) that are on the image I'm trying to achieve
//xAxis.setStandardTickUnits();
xAxis.setTickUnit(new NumberTickUnit(500));
yAxis.setRange(0.0, 130.0);
yAxis.setTickUnit(new NumberTickUnit(10));
yAxis.setInverted(true);
return oChart;
}
I dont know how to make my own set of TickUnits or how to space the domainAxis (xAxis) unevenly.
I'll be glad to read any examples of something like that, so i can try to use it or apply it.
I'll really appreciate your help, is the only thing missing in my project.
I'd like to know if it's possible to put the legend that appears on the chart on the x axis in vertical position. First time I am using JFreeChart and I don't know whether it's possible or not.
This is my actual code
dataset.setValue(VecDias.get(i).GetNpers(),VecDias.get(i).GetHour(),dia_semana);
JFreeChart chart = ChartFactory.createBarChart3D("Estadistica persones/hora", "Hores","Persones",
dataset, PlotOrientation.VERTICAL, true,true, false);
chart.setBackgroundPaint(Color.white);
chart.getTitle().setPaint(Color.black);
CategoryPlot p = chart.getCategoryPlot();
p.setRangeGridlinePaint(Color.red);
LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
ChartPanel chartPanel = new ChartPanel(chart);
panel.add(chartPanel);
You can draw the Category Labels and change their orientation through the JFreeChart object. First get the Axis from the Plot, then change the label orientation
CategoryPlot p = chart.getCategoryPlot();
CategoryAxis axis = p.getDomainAxis();
axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
Note this changes the orientation of the Category labels, so you may have to change how the Dataset object is created such that the names of the Categories are correctly reflected.
I am using jfreechart library to draw a series chart. I have taken values on y-axis, time on x-axis and 3 categories as series. Everything is fine but I'm not able to zoom-in domain axis although it's working fine for range axis. Is this possible?
Following lines of code may help you to find some scenario of my code:
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setDomainZoomable(true);
chartPanel.setRangeZoomable(true);
this.add(chartPanel, BorderLayout.CENTER);
and
//set plot specifications
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(new Color(0xffffe0));
plot.setDomainGridlinesVisible(true);
plot.setDomainGridlinePaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.lightGray);
//CUSTOMIZE DOMAIN AXIS
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
//customize domain label position
domainAxis.setCategoryLabelPositions(
CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
);
It looks like you are using a CategoryPlot which does not support zooing on the domain range
To allow zooming on the Domain axis switch over to a XYPlot if you are using the chart factory the code is
JFreeChart chart = ChartFactory.createXYLineChart(...);
If you are able to cast the plot to an CategoryPlot something has gone wrong. I've checked LineChartDemo3 and this code causes an error (java.lang.ClassCastException):
try {
final CategoryPlot cplot = (CategoryPlot) chart.getPlot();
} catch (Exception e) {
e.printStackTrace();
}
I am using StackedBarChart in the jfreechart API to display no.records in a table which comes from the database. There are 82 tables which im putting on the domain axis and the no. of records in the Range axis. But the problem that I am facing is that because of so many tables in the domain axis, the width of the bar reduces.
Following is my code :
private JFreeChart createChart(CategoryDataset dataset)
{
JFreeChart chart = ChartFactory.createStackedBarChart(
"Stacked Bar Chart", "Task Description", "No_Of_Records", dataset,
PlotOrientation.VERTICAL, true, true, false);
CategoryPlot categoryplot = (CategoryPlot)chart.getPlot();
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setMaximumCategoryLabelWidthRatio(100);
categoryaxis.setLowerMargin(0.02D);
categoryaxis.setUpperMargin(0.02D);
NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
numberaxis.setRange(0.0D, 1000D);
BarRenderer barrenderer = (BarRenderer)categoryplot.getRenderer();
barrenderer.setDrawBarOutline(false);
GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
barrenderer.setSeriesPaint(0, gradientpaint);
return chart;
}
I have tried using a
setItemMargin();
setMaxWidth();
setMaximumBarWidth();
on the BarRenderer, but all in vain..
Any help is appreciated
Regards,
You can experiment with setCategoryMargin(). Also, see how it looks when you right-click and zoom in.
Is there a way to hide a JFreeChart XYSeries yaxis?
The yaxis is meaningless on logic analyzer display.
You can use setVisible(), as shown below.
XYPlot plot = (XYPlot) chart.getPlot();
ValueAxis range = plot.getRangeAxis();
range.setVisible(false);
hide horizontal and vertical labels
ValueAxis range = xyPlot.getRangeAxis();
range.setVisible(false);
ValueAxis domain = xyPlot.getDomainAxis();
domain.setVisible(false);