I am plotting using JFreeChart. By default the XYLineAndShapeRenderer can display tooltips. If I change it to a XYDotRenderer, the tooltips disappear. Am I missing anything? Here is the code snippet
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Test Prices","time","price",dataset,true,true,false);
XYPlot plot = (XYPlot)chart.getPlot();
XYDotRenderer renderer = new XYDotRenderer();
renderer.setDotHeight(10);
renderer.setDotWidth(10);
renderer.setLegendItemToolTipGenerator(
new StandardXYSeriesLabelGenerator("ToolTip {0}"));
plot.setRenderer(renderer);
It's not clear from your snippet whether you want item tooltips or legend tooltips; I will address both:
Unlike XYLineAndShapeRenderer, XYDotRenderer does not include support for chart entities, which is required for item tooltips.
Legend tooltips work correctly.
XYSeriesLabelGenerator legendGenerator = new StandardXYSeriesLabelGenerator();
renderer.setLegendItemToolTipGenerator(legendGenerator);
Related
I am new to Jfreechart. I am creating a 3d pie chart in jfreechart and adding this to pdf using itext api. I am able to generate 3d pie chart dynamically and the tool tip for the pie chart too. I am displaying the plot tool tip in percentage. But for the value that is less then 1, the plot is not getting generate.
Please anyone help me to sort this problem.
Edit: Here is my dataset:
final DefaultPieDataset result = new DefaultPieDataset();
result.setValue("Java", new Double(43.2));
result.setValue("Visual Basic", new Double(10.0));
result.setValue("C/C++", new Double(17.5));
result.setValue("PHP", new Double(32.5));
result.setValue("Perl", new Double(1.0));
result.setValue("dotnet", new Double(0.04));
result.setValue("python", new Double(1.06));
result.setValue("cobol", new Double(0.08));
Pie plot is not getting generated for "dotnet" and "cobol".
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.
As you can see from the picture, the labels for the arrows pointing to the sections of the pie graph are overlapping on the left side. Is there a way to shrink the font of the labels so more can fit? Or make them go out so they dont overlap?strong text
you can rotate chart by some angle by using following code
JFreeChart chart = ChartFactory.createPieChart3D("World Polulation by Countries ", dataset, true, true, true);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setPieIndex(0);
// plot.setLabelFont(new Font("SansSerif", Font.NORMAL, 12));
plot.setNoDataMessage("No data available");
plot.setCircular(false);
plot.setLabelLinksVisible(true);
// plot.zoom(200);
// plot.setStartAngle(180);
// plot.setLabelBackgroundPaint(paint);
plot.setLabelLinkMargin(0.01);
return chart;
How do I plot a bar chart using Dojo ? I have a database with 2 columns empid and empsalary. I want to plot a Bar Chart in dojo with empid as x-axis and empsalary as y-axis. Please suggest.
Thanks in advance
Rahul Kumar
Here is a script to plot a bar chart with Dojo charting:
<script>
require([
// Require the basic chart class
"dojox/charting/Chart",
// Require the theme of our choosing
"dojox/charting/themes/MiamiNice",
// Charting plugins:
// We want to plot Columns
"dojox/charting/plot2d/Columns",
// We want to use Markers
"dojox/charting/plot2d/Markers",
// We'll use default x/y axes
"dojox/charting/axis2d/Default",
// Wait until the DOM is ready
"dojo/domReady!"
], function(Chart, theme) {
// Define the data
var chartData = [10000,9200,11811,12000,7662,13887,14200,12222,12000,10009,11288,12099];
// Create the chart within it's "holding" node
var chart = new Chart("chartNode");
// Set the theme
chart.setTheme(theme);
// Add the only/default plot
chart.addPlot("default", {
type: "Columns",
markers: true,
gap: 5
});
// Add axes
chart.addAxis("x");
chart.addAxis("y", { vertical: true, fixLower: "major", fixUpper: "major" });
// Add the series of data
chart.addSeries("Monthly Sales",chartData);
// Render the chart!
chart.render();
});
</script>
<div id="chartNode" style="width:800px;height:400px;"></div>
Please find detailed explanation here in Dojo tutorials
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();
}