Home
Analytics
Setting height and width of bar chart
techsavvy
Hi,
I have a requirement to accomodate 3-4 bar charts in a single jsp page.
I have integrated the bar charts with the UI,but the size of the charts displayed are too small since there should not be
scroll bars in the web page.
Hence,we have planned to magnify the individual chart in a new window on mouse click of the same.
I tried the following options but is not working out
1) Tried passing the parameters width and height for the same report design file using the 'DrillThrough' option of 'Hyperlink' interactivity.
But this could not set the chart(which is created using 'SVG' option) width and height.
2) Tried if the chart size can be altered locally in BIRT Viewer
Created the chart in 'PNG' format.Used the following code in the initialize method to get a copy of the chart.
var reportDesignHandle = reportContext.getReportRunnable().getDesignHandle();
var re = reportDesignHandle.findElement("NewChart");
var barChart = re.getReportItem().getProperty("chart.instance");
importPackage(Packages.org.eclipse.emf.ecore.util);
var chartCopy = EcoreUtil.copy(barChart);
chartCopy.getBlock().getBounds().setHeight(250); //
chartCopy.getBlock().getBounds().setWidth(150);//
var eih = reportDesignHandle.getElementFactory().newExtendedItem("dupChart", "Chart");
eih.getReportItem().setProperty("chart.instance", chartCopy);
eih.setBookmark(""Chart-" + """);
re.getContainerSlotHandle().add(eih);
(or)
var reportDesignHandle = reportContext.getReportRunnable().getDesignHandle();
var re = reportDesignHandle.findElement("NewChart");
var barChart = re.getReportItem().getProperty("chart.instance");
importPackage(Packages.org.eclipse.emf.ecore.util);
var chartCopy = EcoreUtil.copy(barChart);
var eih = reportDesignHandle.getElementFactory().newExtendedItem("dupChart", "Chart");
eih.getReportItem().setProperty("chart.instance", chartCopy);
eih.setBookmark(""Chart-" + """);
eih.setWidth(100);
eih.setHeight(100);
re.getContainerSlotHandle().add(eih);
Then,used 'Invoke Script' option in the 'Chart Area' interactivity to swap the original chart image with the enlarged image.
imageArray = new Array();
mainImageSrc = document.getElementById("Chart-Main").src;
currentImage = document.getElementById("Chart-" );
imageArray[0] = currentImage;
currentImage.style.display = "none";
function expImg()
{
mainImage = document.getElementById("Chart-Main");
mainImage.src = imageArray[0].src;
}
Though other changes like chartCopy.setUnitSpacing(10) gets reflected in the swapped image,height and width is not set.
Could you please tell if it is possible to change the height and width of bar chart on mouse click.
Thanks,
Kokila
Find more posts tagged with
Comments
mwilliams
Hi Kokila,
I'm not sure that the height and width can be changed on click or not. I haven't been able to achieve this so far.
The following works to change a chart's height and width in the beforeFactory of the report. So, if you could pass the parameters through on a drill through, you could change them with this.
chart = this.getReportElement("ChartName");
chart.setWidth("Width");
chart.setHeight("Height");
mwilliams
This example may also help you get what you're looking for.<br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/devshare/designing-birt-reports/1011-magnify-birt-chart-with-javascript/#description'>Magnify
BIRT Chart with JavaScript - Designs & Code - BIRT Exchange</a>
techsavvy
Hi Michael,
Thanks for your response.
As what you had mentioned,I could pass the report parameters and set the height and width of bar chart in 'beforeGeneartion' as follows:
chart.getBlock().getBounds().setWidth(rpcntx.getParameterValue("repWidth"));
chart.getBlock().getBounds().setHeight(rpcntx.getParameterValue("repHeight"));
I would like to know if it is possible to add more than one interactivity to a charts bar like
1. If one clicks the bar, a magnified chart should be opened in a new window(which is completed using 'drill-through' option).
2. If one moves the mouse over the bar in the magnified chart, a tooltip should appear.(which is not happening though i set the Tooltip at Value Series | Interactivity and then select Mouse Over and Show Tooltip.)
Is it a bug with reference to Bug No-Bug 117986 or has the bug been fixed
Could you please suggest.
Thanks,
Kokila.
mwilliams
Kokila,
The mouse over event doesn't work for tooltip for you? Can you create a report with the sample database that has this issue? As for the magnification of the chart, did you look at the devShare example I linked to? It uses visibility and javascript to switch between a large chart and a small chart.
techsavvy
Hi Michael,
Yes,the mouse over event(for Y-series) for tooltip does not work if i have a mouse click event(for Chart Area) already .Otherwise,if tooltip is the only interactive feature,it works fine.
I looked at the mentioned devshare example,it was really good.But,I enlarged the chart using Drill-through option since it has to open in a new window.
Please find attached a sample report.I need to show tooltip for the magnified chart which appears on click of the small chart.
Could you please suggest.
Thanks,
Kokila.
mwilliams
Kokila,<br />
<br />
It seems like a bug to me that this doesn't work. You can log a bug for this at <a class='bbc_url' href='
http://www.eclipse.org/birt/phoenix/reportabug.php'>BIRT
: Reporting Bugs and Requesting Enhancements</a>.<br />
<br />
As a way around it, since you're opening your chart in another window through drill through, you could make a separate report with the chart in it as a bigger size and only have the mouse over event on this one?
techsavvy
Hi Michael,
Thanks for the info.
I think it has already been logged as a bug with reference to Bug No-117986
Yes,I could do as what you said (make a separate report with the chart in it as a bigger size..... ) but there are many charts that has to be created and having 2 reports for each chart will make it a redundant info.
Also,I have an other doubt.When I click on the chart in the attached sample report,it opens up in a new window infinite number of times for every click and hence i have used the following code in the beforeRendering function.
gcs.getChartModel().getInteractivity().setEnable(false);
Suppose,if we assume that tooltip is enabled for the chart,then the above code will make tooltip disabled eventhough its set on 'mouseover' event(for the magnified chart).
Could you please clarify.
Thanks,
Kokila
mwilliams
Kokila,
I'll look and see if there's a way to just clear the drill through off the chart and leave the tooltip. I'll let you know if I find anything.