Heatbar, dynamic position offset of text - charts

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:

Related

Retrieving a text string from a xml document

I am trying to retrieve the string "This is my string" that belongs to text id="short_name
I have tried:
$SVGTemplate = Get-Content "C:\temp\sample.svg
$SVGTemplate = [XML]$SVGTemplate
$SVGTemplateShortName = Select-Xml -Xml $SVGTemplate -XPath '/s:svg/s:g/s:g[#id="short_name"]/s:text/text()' -Namespace #{s = "http://www.w3.org/2000/svg"}
$SVGTemplateShortName.node.value
But it returns an empty value. This used to work before and recently broke because I had to redesign the svg graphic.
I have tried to correct the XPath many times and it keeps returning an empty value. What could I be doing wrong?
Below is my xml file.
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 26.5.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 500 500" style="enable-background:new 0 0 500 500;" xml:space="preserve">
<style type="text/css">
.st0{fill:#E30613;}
.st1{fill:#FFFFFF;}
.st2{fill:#009FE3;}
.st3{fill:none;}
.st4{font-family:'MyriadPro-Regular';}
.st5{font-size:88px;}
.st6{fill:#008D36;}
</style>
<g id="background">
<rect id="stroke" class="st0" width="500" height="500"/>
<rect id="Fill" x="12" y="12" class="st1" width="476" height="476"/>
</g>
<g id="short">
<rect id="short_fill" x="12" y="400" class="st2" width="476" height="100"/>
<rect y="412" class="st3" width="500" height="88"/>
<text id="short_name" transform="matrix(1 0 0 1 87.7305 474.4795)" class="st1 st4 st5">This is my string</text>
</g>
<g id="hud">
<rect id="left" x="12" y="12" class="st6" width="92" height="76"/>
<rect id="right" x="396" y="12" width="92" height="76"/>
</g>
<g id="graphic">
<g id="Card_Symbl">
<g id="Layer_10">
<polygon class="st0" points="309.9,387.1 396.3,124.5 303.1,105.8 96.5,251.1 "/>
</g>
</g>
</g>
</svg>
If you want to locate an element by its full path, an easier way is to use PowerShell's member access:
$SVGTemplate.svg.g.text | Where-Object id -eq 'short_name' | ForEach-Object '#text'
... or more succinct, using intrinsic .Where method:
$SVGTemplate.svg.g.text.Where{ $_.id -eq 'short_name'}.'#text'
XPath does have an advantage if you want to locate an element regardless of how deep it is nested (relative path, introduced by double slash):
$SVGTemplate |
Select-Xml -XPath '//s:text[#id="short_name"]' -Namespace #{s = "http://www.w3.org/2000/svg"} |
ForEach-Object { $_.Node.'#text' }
Of course it also works using the absolute path (introduced using single slash), but is much more lengthy than its member access counterpart:
$SVGTemplate |
Select-Xml -XPath '/s:svg/s:g/s:text[#id="short_name"]' -Namespace #{s = "http://www.w3.org/2000/svg"} |
ForEach-Object { $_.Node.'#text' }
The original XPath expects a <g> tag with an id attribute and a value of "short_name"... however the XML does not contain such a path. Was it supposed to read `/s:text[#id="short_name"]?
Other than that, yes anyone can use PS´s "human-friendly" access methods... though there is a bit of an inherent danger there when there is no schema attached to the XML or when trying to access optional nodes that might or might not be there for a given path.
PS works with lists. XML paths break when using $xmlDoc.tagA.tagB.tagC notation; assuming this is not $null and is a list longer than exactly one (1) node then we have no way of telling where in the XML and under possibly what conditions we got those nodes from.
... When in doubt: don't.

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.

Draw mysterious Pie Chart - wrong percentage in Slice

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).

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

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.