Draw mysterious Pie Chart - wrong percentage in Slice - jasper-reports

I am using Jaspersoft Studio and JasperReports Server, both in v.5.6.0.
I want to create a Pie Chart that shows the percentage of Errors colored in red.
Example:
$V{til_1} = total$V{state_1} = errors
total:2 - errors:1 => should result in a Pie Chart with 2 Slices -> 50% Red and 50% Green.
I used 2 Series, one Serie (Keyexpression) "green" (value 100.0), one Serie (Keyexpression) "red" (value: $V{state_1}>1?0:new Float(($V{state_1}*100)/$V{til_1}) ).
<pieChart>
<chart isShowLegend="false">
<reportElement x="293" y="0" width="30" height="30" uuid="8369e35a-d6d6-4e0d-aa6e-fef7a118ecce"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset>
<pieSeries>
<keyExpression><![CDATA["green"]]></keyExpression>
<valueExpression><![CDATA[100.0]]></valueExpression>
<labelExpression><![CDATA[null]]></labelExpression>
</pieSeries>
<pieSeries>
<keyExpression><![CDATA["red"]]></keyExpression>
<valueExpression><![CDATA[$V{state_1}>1?0:new Float(($V{state_1}*100)/$V{til_1})]]></valueExpression>
<labelExpression><![CDATA[null]]></labelExpression>
</pieSeries>
</pieDataset>
<piePlot isShowLabels="false">
<plot>
<seriesColor seriesOrder="0" color="#99FF99"/>
<seriesColor seriesOrder="1" color="#CC0000"/>
</plot>
<itemLabel/>
</piePlot>
</pieChart>
Actual result (including the Problem):
However, when I run the report the calculation for "red" seams to be correct, the Chart output-image does not - link to image attached below. (50%red instead of 100% and 33,3%red instead of 50%)
Image:
Somebody knows where my mistake/how to get the right percentage in Pie Chart and -if possible- a short explanation why does jasper draw wrong chart-slices? Because of the two Series?

I believe that your problem is: the chart doesn't know what percentage is.
Actually, when you say to it "print serias A as 100" and "print series B as 50" it's going to assume 100% (the total, the full chart) is A + B, which is 150. Then, your series B will show as 33.3% of your total.
So basically, you will need to manually work out your "proportions". For example:
If you have "red" as $V{state_1} > 1 ? 0 : (new Float($V{state_1})/$V{til_1})*100, you can use your "green" as 100 - ($V{state_1} > 1 ? 0 : (new Float($V{state_1})/$V{til_1})*100).

Related

How to auto-wrap if total html or component properties >= n?

As I understand with the default settings in vscode. The properties below will only auto-wrap when it reaches to the maxiumum wordWrapColumn. (See below)
<h1 className="sample" height="20" width="30" color="20" size="200" />
// auto separated
<h1
className="sample"
height="20"
width="30"
color="blue"
size="200"
/>
I wanna ask if its possible to change this behavior? Instead of basing to wordWrapColumn, we check the total properties of an element / component.
We auto-newline when it reaches to the specified total props.
totalHtmlProps = 3
## case 1
<h1 className="sample" height="20" />
## case 2
<h1
className="sample"
height="20"
color="blue"
/>
a quick update: i'm also using prettier with this.

Heatbar, dynamic position offset of text

I want to insert a new column in my report to graphically display a "needle" displaying the position in a range of 0% - 100% like so:
I am looking for ideas please!
My idea
Use graphic (rainbow 0%-100% in every detail column).
Use a pixel offset (somehow??) where I simply place an overly large "|" type. So if 0%-100% are 200px that would mean that to display the needle at 50% I would offset the type 100px!
The easiest / most straightforward option I have found and implemented:
<image scaleImage="RetainShape" onErrorType="Blank">
<reportElement x="575" y="1" width="100" height="13" uuid="7cf54aff-65ac-40e5-8dc9-7f95d6f34d49"/>
<imageExpression>
<![CDATA[net.sf.jasperreports.renderers.BatikRenderer.getInstanceFromText("
<svg id=\"Layer_1\" data-name=\"Layer 1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"100\" height=\"13\" viewBox=\"0 0 100 13\">
<defs>
<linearGradient id=\"linear-gradient\" x1=\"-176.88\" y1=\"316.13\" x2=\"-150.45\" y2=\"316.13\" gradientTransform=\"matrix(3.78, 0, 0, -3.78, 689.01, 1202.56)\" gradientUnits=\"userSpaceOnUse\">
<stop offset=\"0\" stop-color=\"green\"/>
<stop offset=\"1\" stop-color=\"green\" stop-opacity=\"0\"/>
</linearGradient>
</defs>
<path d=\"M0,1.26H100v10.4H0Z\" style=\"fill: url(#linear-gradient)\"/>
<path d=\"M" + !!! OFFSET CALCULATION !!! + ",0V13\" style=\"fill: none;stroke: #000\"/>
</svg>
")]]></imageExpression>
</image>
Result:

removing extra space from top and left when using formitems in flex

I want to remove the extra space/padding/gap from FormItem I,m using in form for a mobile project in flex 4.6
I have tried making gap and padding to 0 but there the form and it's fields are still have indent to the right and top ?
<s:FormItem label="Start Date" width="150">
<s:HGroup>
<s:TextInput id="startDate" width="90" editable="false"/>
<s:Button id="setStartDate" label="set" height="34" fontSize="10" click="setStartDate_clickHandler(event)"/>
</s:HGroup>
</s:FormItem>
<s:FormItem label="End Date" width="150">
<s:HGroup>
<s:TextInput id="endDate" width="90" editable="false"/>
<s:Button id="setEndDate" label="set" height="34" fontSize="10" click="setEndDate_clickHandler(event)"/>
</s:HGroup>
</s:FormItem>
</s:HGroup>
</s:Form>
Gap between two form items, verticalGap.(set it on Form container)
Default hgroup gap is 6, set it to 0.
If gap between two items withn the FormItem, verticalGap (set this on the form container)
Form has FormHeading, set paddingTop=0 on this FormHeading comp. Also, try to set the height of this to 0 and PaddingTop = 0 on the form to reduce the gap btwn the first element and the top of the Form container.
This has good information about it http://livedocs.adobe.com/flex/3/html/help.html?content=layouts_08.html

How to design GridView to display with scrolling

How to design GridView in such a way that it display 3 images per row and can be scrolled up for the other Images behind? it seems this gridView displays images in a row.
Below I have 8 Pic in Gridview:
1) How to setup GridView to displays images with(3 images per row) or without specifying number of images per row and the rest will be viewed by scrolling up?
Thanks
< GridView HorizontalAlignment="Left" Margin="30,200,0,0" Grid.Row="1" VerticalAlignment="Top" Width="800" Height="400" >
//-- pic 1
< GridViewItem>
< Grid HorizontalAlignment="Left" Width="200" Height="200">
< Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}">
< Image Source="Images/M123.jpg" Tag="name" Tapped="Image_Tapped_1" Stretch="UniformToFill"/>
< /Border>
< StackPanel VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}">
< TextBlock FontSize="30" Text="name" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}"
Style="{StaticResource TitleTextStyle}" Height="40" Margin="15,10,15,0"/>
</StackPanel>
</Grid>
</GridViewItem>
//- pic 2 using GridViewItem
//-- pic 3 using GridViewItem
//--- Pic 3 to Pic 8 GridViewItem
< / GridView>
Put the grid view in a scrollviewer and let the height of the gridview be auto ie it will take the height of the entire content and width of the grid view to a specific one so that t cqn take only 3 items
next step is to just enable the vertical scroll property of the scroll viewer and disable the horizontal scroll property.
i hope this solves the purpose .
try to use jquery plugin
http://gridviewscroll.aspcity.idv.tw/
function gridviewScroll() {
$('#<%=gvMain.ClientID%>').gridviewScroll({
width: 700,
height: 330,
freezesize: 2,
arrowsize: 30,
varrowtopimg: "Images/arrowvt.png",
varrowbottomimg: "Images/arrowvb.png",
harrowleftimg: "Images/arrowhl.png",
harrowrightimg: "Images/arrowhr.png",
headerrowcount: 2
});
}

iReport displays too many labels on x axis

Good morning! I'm having a problem with Jaspersoft iReport 4.5.0, and I was hoping for some help. Basically, when I display an xy line chart, it's attempting to add a label on the x-axis for each data point. I have almost 200 data points, so this ends up looking like just a solid line, even if I tweak the rotation of the tick labels or whatever.
I'm aware that the general response to this question is to use a timeseries chart instead. This would ordinarily work, but in my instance I am using a multi-axis chart where the opposite axis is a bar chart. Since a bar chart has no timeseries variety, iReport will not allow me to mix a bar chart with a timeseries chart, forcing me to use the xy line chart.
Is there any way I can have my cake and eat it, too? Some way I can filter out some of the labels? Or perhaps limit the number of labels that can be displayed, spread out over the x-axis? I have yet to see a definitive answer anywhere on the internet!
Thanks in advance!
- Ian
EDIT: Here is the jrxml for one of the multi-axis charts I'd like to modify:
<multiAxisChart>
<chart evaluationTime="Report" hyperlinkType="LocalAnchor">
<reportElement x="42" y="441" width="440" height="292"/>
<chartTitle position="Top">
<titleExpression><![CDATA["CICS Elapsed"]]></titleExpression>
</chartTitle>
<chartSubtitle/>
<chartLegend/>
<anchorNameExpression><![CDATA["CICS Elapsed Small"]]></anchorNameExpression>
<hyperlinkAnchorExpression><![CDATA["CICS Elapsed Big"]]></hyperlinkAnchorExpression>
<hyperlinkTooltipExpression><![CDATA["Click to Enlarge"]]></hyperlinkTooltipExpression>
</chart>
<multiAxisPlot>
<plot/>
<axis position="leftOrTop">
<lineChart>
<chart>
<reportElement x="0" y="0" width="0" height="0" backcolor="#FFFFFF"/>
<chartTitle position="Top" color="#000000">
<titleExpression><![CDATA["CICS Elapsed"]]></titleExpression>
</chartTitle>
<chartSubtitle color="#000000"/>
<chartLegend textColor="#000000" backgroundColor="#FFFFFF"/>
</chart>
<categoryDataset>
<dataset>
<datasetRun subDataset="wmprod_cics"/>
</dataset>
<categorySeries>
<seriesExpression><![CDATA["Cpu Time"]]></seriesExpression>
<categoryExpression><![CDATA[$F{TIMESTAMP}]]></categoryExpression>
<valueExpression><![CDATA[$F{ELAPSTIME}]]></valueExpression>
</categorySeries>
</categoryDataset>
<linePlot isShowShapes="false">
<plot/>
<categoryAxisLabelExpression><![CDATA["Date/Time"]]></categoryAxisLabelExpression>
<valueAxisLabelExpression><![CDATA["Avg Elapsed Time (ms)"]]></valueAxisLabelExpression>
</linePlot>
</lineChart>
</axis>
<axis position="rightOrBottom">
<barChart>
<chart>
<reportElement x="0" y="0" width="0" height="0" backcolor="#FFFFFF"/>
<chartTitle position="Top" color="#000000">
<titleExpression><![CDATA["CICS Elapsed"]]></titleExpression>
</chartTitle>
<chartSubtitle color="#000000"/>
<chartLegend textColor="#000000" backgroundColor="#FFFFFF"/>
</chart>
<categoryDataset>
<dataset>
<datasetRun subDataset="wmprod_cics"/>
</dataset>
<categorySeries>
<seriesExpression><![CDATA["Volume (transactions)"]]></seriesExpression>
<categoryExpression><![CDATA[$F{TIMESTAMP}]]></categoryExpression>
<valueExpression><![CDATA[$F{TRANSCOMPL}]]></valueExpression>
</categorySeries>
</categoryDataset>
<barPlot>
<plot/>
<itemLabel/>
<valueAxisLabelExpression><![CDATA["Volume (transactions)"]]></valueAxisLabelExpression>
</barPlot>
</barChart>
</axis>
</multiAxisPlot>
</multiAxisChart>
I had the same problem. I think the answer is this:
<chart>
<reportElement x="0" y="0" width="802" height="215">
<property name="net.sf.jasperreports.chart.domain.axis.tick.interval" value="1"/>
</reportElement>
Set the tick interval as appropriate. Note: My chart was a scatter chart. Untested with line chart.