I am using Jaspersoft Studio to create the report file with charts.
When I use the bar chart and try to display the bar values labels these are covered by the margins. In my opinion this looks like a bug, is there any way to show the labels properly?
To better illustrate the problem you can see the issue on the picture and also find in red the expected values.
EDIT
Here is my progress customizing the bar chat. So far I could make several changes but I am stuck with the most important one.
I tried using huge values for the margins without any visual effect.
rangeAxis.setUpperMargin(200);
rangeAxis.setLowerMargin(200);
I also played with the bounds. In that case I can see the entire labels but the problem is that the values won't stop at 100 (so that is not a valid solution).
I discovered the reason why the margins are completely ignored:
public void setUpperMargin(double margin)
Sets the upper margin for the axis (as a percentage of the axis range) and sends an AxisChangeEvent to all registered listeners. This margin is added only when the axis range is auto-calculated - if you set the axis range manually, the margin is ignored.
But if I remove the margins then the bounds are autocalculated from 0-125 what is not the scope.
As usual, any suggestion will be welcome.
For a better understanding you can download the sample code from my GitHub repository.
GitHub: https://github.com/MichaelKnight/jaspertest.git
The chart in jasper report is generated by the jfreechart library. In your case you can:
1) Set the range axis upper margin to give more space to value label (see jfreechart BarChartDemo5).
2) Draw the label inside the bar (see jfreechart BarChartDemo7) After edit if you need fixed upper value of axis you need to use this, hence the label has no space left if upper limit equals max bar value
To customize your bar chart in jasper report create a customizer class (MyChartCustomizer) extending the JRChartCustomizer. This will expose:
public void customize(JFreeChart chart, ChartComponent chartComponent)
{
//Simple example of increasing upper margin on range axis, to print label
//inside of bar see jfreechart BarChartDemo7
CategoryPlot plot = (CategoryPlot) chart.getPlot();
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setUpperMargin(0.20); //Increase or decrease to change upper margin in percentages (0 --> 1.0)
rangeAxis.setAutoRange(true); //make sure that fixed range is not set
}
add the class to classpath and in jrxml set the customizerClass attribute
<barChart>
<chart customizerClass="my.package.MyChartCustomizer">
....
</chart>
...
</barChart>
Related
I am working on a butterfly chart. I create a center zero axis with "Text" type. Everything goes fine, except for one thing.
The width of the center axis is too broad, I want to change the width. But I don't know how to do it.
If I shrink the center axis, left and right are also shrunk. It seems the ratio of width is fixed.
Here is my demo workbook on Tableau Public.
Thanks for any help.
I was able to recreate your butterfly chart following the steps below.
"Concatenated by Dashboard
To shrink the middle margin, we can use a dashboard to concatenate instead of a single worksheet.
Divide into three Worksheets: right-click on the sheet tab and duplicate three copies. Remove the other parts in each worksheet.
Create a Dashboard and concatenate three segments: drag these segments to the corresponding positions.
Change the Dashboard Size to 1200 x 4500. concatenated by dashboard
Set left and right segments as Standard and set the middle segment as Fit Width. Then, Resize them to a proper layout.
Right-click Legends and check Floating, then put them in the appropriate place.
Polish the chart:
Keep only the left title and remove others.
show and rename the left and right axis."
Source: https://www.pluralsight.com/guides/tableau-playbook-diverging-bar-chart
I have created a BIRT report with multiple charts.
All the charts include different data but for the same time span.
So i want to make the x axis of the charts align with each other so it is easy to read all the charts at once.
But the series names of these charts are different from each other.And some charts gets dynamic series names in which the length cannot be predicted.
Even though i align the charts with same width and height because of the series names the legend gets too lengthy and the alignment gets ruined.
According to the requirements given to me legend should be placed at the right side of the chart.
Is there a way to fix the size of the legend without truncating the series names.May be a way to wrap the series names so the size of the legend will be same for all the charts and the charts will be aligned nicely.
From your Eclipse designer:
Edit charts -> Format charts -> Legend -> Layout -> Wrapping width
Set a wrapping width value as expected, for example try 60.
You might also have to increase the bottom inset of legend entries to avoid overlapping:
Edit charts -> Format charts -> Legend -> Entries -> Bottom inset
From your Eclipse designer: set Format Chart->Legend->Entries->Ellipsis property to possible max length of your dynamic legends. and the problem will be solved.
As this property work as follows:
The default value is "1". Int attribute "Ellipsis" specifies the behavior of shortening the legend item's text with ellipsis if there is not enough space to display the whole text. Value 0 indicates that the feature is disabled, and the legend item will either be displayed with whole text or be dropped. A positive value n represents the minimal count of characters to be displayed before the ellipsis, which means the legend item will either be dropped or be displayed with at least n characters.
Hope this will solve your problem. It worked for me.
how can I move yAxis labels from Right of chart to left of chart in highstock.
Here is a jsfiddle example in which we have labels like Fresh Breeze on the right side of chart which I want it on the left.
In the previous version of Highstock it is was on left by default.
I have also tried the property align:left inside the yAxis options but it does not give the desired result.
Thanks
You don't want to set align:left at the axis level, you need to use it on the plotband label level.
The code in that example is explicitly telling the chart to align the plot band labels to the right, and push them an extra 40 pixels right as well.
Change that to align:left, and x:0
(or, just don't set the align or x properties at all, and by default the labels will be on the left, as they've always been...)
example:
http://jsfiddle.net/jlbriggs/LKtpc/28/
{{EDIT:
Your original question referenced the plotband labels in highcharts...
But it seems your question is really about the y axis placement in Highstock.
To move it to the left, you need to add this:
yAxis: {
opposite:false
}
as Highstock sets the axis to opposite:true by default.
Example:
http://jsfiddle.net/aayajgLe/1/
In order to put your yAxis label to the left side, just set yAxis' opposite property to false.
yAxis: {
opposite: false
}
It seems not intuitive, though.
I'm using a dojo chart to display data in a bubble chart. However, I don't need the axis but if I remove the axis, it screws up the display of the data. I can fudge axis not being there by hiding labels and coloring the lines white but then there's still this large margin on the left and bottom of the chart. How do you make a dojo chart without the axis while still having the min/max set correctly?
chart1.addAxis("x",{ type : 'Invisible' /*, .... */ });
Matthew, if you are still looking to tweak the margins, the solution here:
dojox charting: remove the padding around the chart
worked for me.
I am creating a Chart (DataVisualization.Charting.Chart) programmatically, which is a Stacked Bar chart.
I am also adding Legend entries programmatically to it. I want to show the Legend at the bottom of the chart.
But, while doing so, the Legend overlapps with the X-axis of the chart.
Here is the code I am using:
Private Function GetLegend(ByVal legendName As String, ByVal s As Single) As System.Windows.Forms.DataVisualization.Charting.Legend
Dim objLegend As System.Windows.Forms.DataVisualization.Charting.Legend = New System.Windows.Forms.DataVisualization.Charting.Legend()
objLegend.Name = legendName
objLegend.Font = New System.Drawing.Font("Verdana", s)
objLegend.IsDockedInsideChartArea = False
objLegend.Docking = Docking.Bottom
Return objLegend
End Function
Below statement adds that Legend to the chart
_msChart.Legends.Add(GetLegend("SomeValue1", 10.0F))
Any idea, what is missing? I want to show the legend at the bottom only, but it should not overlapp with the X-axis.
I had the same problem today. Try adding:
objLegend.Position.Auto = true
objLegend.DockedToChartArea = "yourChartAreaName"
That did not help me but I found on the net that this might be helpful (and clean solution).
What actually worked for me was moving chart area to make space for legend so it no longer overlaps. My legend was on top so this code worked for me:
chart.ChartAreas[0].Position.Y = 15
You can try resizing it instead, forcing it to be for example 20 pixels shorter than chart.Size.
Hope this helps.
I had an overlapping legend/chart area problem as well but none of the other suggestions here seemed to make any difference. I think the problem stems from legend text wrapping to two lines and the sizing algorithms not taking account of this.
The ideas here got me thinking more clearly about the problem though, and I was able control the size and position of the chart area using the following.
Chart1.ChartAreas[0].InnerPlotPosition = new ElementPosition(15, 5, 90, 75);
There's not much intellisense on those parameters, but as well as I could deduce, the parameters are all percentages of the total chart area (I initially thought they might be pixel values and got some very odd results). So what I've written above would set the plot area to start at 15% in from the left edge of the chart image and 5% down from the top, and have a width of 90% and a height of 75%.