I have Created one Barchart in ireport 3.0, the problem is that the bars are very thin. When i tried to increase bar width through customize r class it doesn't reflect any changes in size of bar i.e. width is same as it was. So how to increase width of bars of bar chart? I am attaching an image copy for your understanding purpose.
Bar width is shown in figure.
I have faced same issue as well. After a long search i found some solutions which fixed my issue. jasper report bar chart's bar width depends on chart's height and width. as jasper use JFreechart in backend so many modifications possible by a customize class. For increasing bar's width you need a customization class and then add it to your barchart jrxml like bellow
public class JasperBarChartCustomization implements JRChartCustomizer {
#Override
public void customize(JFreeChart chart, JRChart jasperChart) {
CategoryPlot catPlot = (CategoryPlot) chart.getPlot();
BarRenderer renderer = (BarRenderer) catPlot.getRenderer();
renderer.setMaximumBarWidth(.08);//for max width//
renderer.setItemMargin(-2);//as much margin decrease that much bar width increase//
//for adding value ob bar//
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
renderer.setBaseItemLabelPaint(Color.WHITE);
renderer.setBaseItemLabelFont(new Font("fontname", Font.PLAIN, 6));
//for remove legend background color and box border//
if (chart.getLegend() != null) {
chart.getLegend().setBorder(0.0, 0.0, 0.0, 0.0);
LegendTitle legend = chart.getLegend();
legend.setBorder(0, 0, 0, 0);
legend.setFrame(BlockBorder.NONE);
}
}
}
Now create a jar from above class and use that jar in ur jasper project's classpath
If your jasper run inside java application then u can use the class directly without making jar. create customize class in you code base
Related
I've added a nvd3 chart to my sencha touch app.
Apparently though the size of the box where the chart will be inserted is undefined at the time the chart is created. This turns out in a graph with standard dimensions (960x350 approx), way too large!
How can I modify the widht and height of the chart? The visual error I get is that the chart has a larger width, the component containing it are smaller and the chart is not completely
visible (it's like it misses a resize effect to adapt its size to the containing box).
My code, which is inside a sencha component goes like this:
nv.addGraph(Ext.bind(function(){
var chart = nv.models.discreteBarChart()
.x(function(d) { return d.label; })
.y(function(d) { return d.value; })
.staggerLabels(true)
.tooltips(false)
.showValues(true);
var w = 550;
var h = 280;
var svg = d3.select(this.innerElement.dom).append('svg');
// setting axis property doesn't work:
var x = d3.scale.ordinal()
.domain(d3.range(10))
.rangeRoundBands([0, w], 1);
chart.xAxis
.tickFormat(d3.format(',f'));
chart.xAxis.scale(x);
chart.yAxis
.tickFormat(d3.format(',f'));
//setting svg properties doesn't work:
svg.attr("width", w)
.attr("height", h);
svg.datum(this.getChartData()).transition().duration(500).call(chart);
//if I comment this, nothing changes, what is this method for?
nv.utils.windowResize(chart.update);
I've made a MultiBarChart with NVD3.
It works, however, a colleague said I needed more space between each Australian state.
So, Tasmania further from Victoria etc.
Here is the data visualisation
I can not find a forum that explains this in non-developer language. I'm not a developer, but having a go.
Here is my code...
var chart;
nv.addGraph(function() {
chart = nv.models.multiBarHorizontalChart()
.x(function(d) { return d.label })
.y(function(d) { return d.value })
.margin({top: 30, right: 105, bottom: 30, left: 103})
.tooltips(true)
.showControls(false);
chart.yAxis
.tickFormat(d3.format(',.1f'));
d3.select('#chart1 svg')
.datum(long_short_data)
.transition().duration(1400)
.call(chart);
nv.utils.windowResize(chart.update);
chart.dispatch.on('stateChange', function(e) { nv.log('New State:', JSON.stringify(e)); });
return chart;
});
Thanks you super kind and smart people!
No Need to use too much code for spacing just use below code :
var chart = nv.models.multiBarChart();
//added by santoshk for fix the width issue of the chart
chart.groupSpacing(0.8);//you can any value instead of 0.8
This is unfortunately something you can't configure in NVD3. However, you can change the height of the bars after the chart has been created to make it appear as if there's more space between them. The code to do this is simple:
d3.selectAll(".nv-bar > rect").attr("height", chart.xAxis.rangeBand()/3);
The default height is chart.xAxis.rangeBand()/2 -- you can adjust this as you see fit. The only thing to keep in mind when running this code is that NVD3 animates its elements, so not everything will be there in the beginning or values may be overwritten. You can solve this by waiting a small amount of time before calling that code using setTimeout:
setTimeout(function() {
d3.selectAll(".nv-bar > rect").attr("height", chart.xAxis.rangeBand()/3);
}, 100);
Just found this question while searching for a way to add more space between bars. Like Lars said, you can change the bar size after the chart has been drawn. However, when you increase the bar height without changing the space between each bar, it overflows. To add space between the bars you should use xRange:
var chart = nv.models.multiBarHorizontalChart().xRange([0, 125])
Hi All Iam using itextpdf-5.1.0.jar, displaying Table(the values in this table are fetched from the database based on start date and end date in the input screen) and bar chart for the values in the above table.
The problem is I want to position the bar chart below the table, values that iam fetching from the database may vary depending upon start date and end date, now Iam positioning table and bar chart by giving some static values(234,567) , if there are large no of values table values and bar chart are getting overrided. Is there any other way to position table and bar chart dynamically.
Document document = new Document(PageSize.A4_LANDSCAPE, 10, 10, 10, 10);
document.open();
document.add(new Paragraph("Batch Report:", FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD, new CMYKColor(255, 255, 255, 255))));
Paragraph paragraph1 = new Paragraph();
paragraph1.setSpacingBefore(4);
document.add(paragraph1);
PdfPTable table = new PdfPTable(5);
table.setWidthPercentage(100);
PdfPCell c1;
for (BoardBean bean : listHeader) {
addColumn(bean.getID(),c1,table,myColor,btableheadercolor);
}
Add Column values to table
private void addColumn(String text,PdfPCell c1,PdfPTable dataTable,BaseColor myColor,BaseColor btablecolumncolor) {
try {
final Font tabletdcolor = new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL, BaseColor.BLACK);
c1 = new PdfPCell(new Paragraph(text, tabletdcolor));
cellStyle(c1, myColor, btablecolumncolor);
dataTable.addCell(c1);
} catch (Exception ex) {
ex.printStackTrace();
}
}
Generating bar chart
JFreeChart reportBarChart = genBatchReportBarChart(listHeader);
PdfTemplate reportTemplate = contentByte.createTemplate(280, 230);
Graphics2D reportGraphics = reportTemplate.createGraphics(280, 230, new DefaultFontMapper());
Rectangle2D reportRectangle = new Rectangle2D.Double(0, 0, 280, 230);
reportBarChart.draw(reportGraphics, reportRectangle);
reportGraphics.dispose();
contentByte.addTemplate(reportTemplate, 10, height+150);
Now in the above code iam fixing the position of bar chart and if the values are low in number its good but if they are large in number bar chart is overriding the table values.Depending upon the table values the bar chart need to be aligned how can I achieve that.
You can ask the table for its total height after you've added the table to the document, and use that table height to decide where to put the chart.
Or (even easier to achieve): you can wrap the PdfTemplate inside an Image object:
Image img = Image.getInstance(reportTemplate);
Add that image with document.add() right after you've added the table (assuming that you're adding the table with document.add()).
Just noticed that the pie-chart that is displayed is not utilizing the full width and height of the container.
I can see some blank spaces. Attached image below.
I have drawn borders to the div. And it is clear that the pie isn't utilizing the full width and height.
How do i get this thing fixed?
Any help would be appreciated.
Thanks in advance.
It looks like the default piechart renderer has a padding of 20px. Reduce it as you see fit by adjusting the padding such as:
jQuery("#'. $id .'").jqplot([your data here],
{
seriesDefaults: {
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
padding: 10
}
}
});
I want to display three or more DataGrids in my LayoutPanel and specify their width as a percentage of the total width of the LayoutPanel, but in the LayoutPanel methods i see only methods for setting the width of the left and right widgets. setWidgetLeftWidth() and setWidgetRightWidth().
Is it possible to add more than 2 widgets to a LayoutPanel like
layoutPanel.add(dataGrid1);
layoutPanel.add(dataGrid2);
layoutPanel.add(dataGrid3);
layoutPanel.add(dataGrid4);
and then set the width of each widget to be 25% of the width of the LayoutPanel?
Thanks and regards
Mukul
What you have will work, all you need to do is to make each one setup like the following:
layoutPanel.add(dataGrid1);
layoutPanel.setWidgetLeftRight(dataGrid1, 0, Unit.PCT, 25, Unit.PCT);
Well I think you could do it with LayoutPanel too, but using the DockLayoutPanel is much easier! Here is the code for a the example you tried with a LayoutPanel.
public void onModuleLoad() {
//define a DockLayoutPanel with a Percentage size definition
DockLayoutPanel dockLayoutPanel = new DockLayoutPanel(Unit.PCT);
//add four widgets to the DockLayoutPanel, each with a Percentage
//with of 25%
dockLayoutPanel.addWest(new Label("widget 1"), 25);
dockLayoutPanel.addWest(new Label("widget 2"), 25);
dockLayoutPanel.addWest(new Label("widget 3"), 25);
//the last widget must always be added with the .add method
//since it takes the rest of the screen
dockLayoutPanel.add(new Label("widget 4"));
//set a with to the DockLayoutPanel (elso you don't se much)
dockLayoutPanel.setWidth("500px");
dockLayoutPanel.setHeight("500px");
//add it to the RootPanel
RootPanel.get().add(dockLayoutPanel);
}
So as long as you don't have a good reason why you must use LayoutPanel, I'd use the DocklayoutPanel!