Telerik RadHtmlChart Pie Chart Error - telerik

I am attempting to use the RadHtmlChart pie chart, but I'm getting the following error:
Cannot create an object of type 'System.Nullable from its string representation 'StatCount' for the 'Y' property.
If I use the same SqlDataSource for an asp:Chart it works as expected. So my guess is that is this specific to the RadHtmlChart - but it's just a guess.
The query (MS SQL Server 2012) returns the following:
+----------------------+-----------------+
| stat | StatCount |
+----------------------+-----------------+
| Closed | 4067 |
+----------------------+-----------------+
| Pending Assignment | 1 |
+----------------------+-----------------+
| QA Ready | 600 |
+----------------------+-----------------+
| In QA | 400 |
+----------------------+-----------------+
| Assigned | 4946 |
+----------------------+-----------------+
Here's the SqlDataSource I'm using to get this data:
<asp:SqlDataSource
ID="sdsAssnmtStats"
runat="server"
ConnectionString='<%$ ConnectionStrings:DefaultConnection %>'
SelectCommand="SELECT s.stat ,cast(case s.stat when 'Pending Assignment' then count(a.clmNo) when 'Assigned' then count(a.clmNo) when 'QA Ready' then count(a.clmNo) when 'In QA' then count(a.clmNo) when 'Closed' then count(a.clmNo) else 0 end as nvarchar) as StatCount FROM assnmts a inner join assnmtStats astats on a.assnmtIdPk = astats.assnmtIdFk inner join stats s on astats.aStatId = s.statIdPk inner join repAssnmts ra on a.assnmtIdPk = ra.assnmtIdFk inner join aspnetusers anu on ra.repId = anu.Id inner join clients c on a.clientIdFk = c.clientIdPk inner join carrs on a.carrierId = carrs.carrIdPk inner join (SELECT a2.assnmtIdPk, MAX(astats2.asCrtdDt) as MaxDate FROM assnmts a2 INNER JOIN assnmtStats astats2 on a2.assnmtIdPk = astats2.assnmtIdFk GROUP BY a2.assnmtIdPk) mdt on a.assnmtIdPk = mdt.assnmtIdPk and astats.asCrtdDt = mdt.MaxDate inner join (select a3.assnmtIdPk, MAX(ra2.raCrtdDt) as MaxRepDate from assnmts a3 inner join repAssnmts ra2 on a3.assnmtIdPk = ra2.assnmtIdFk group by a3.assnmtIdPk) mrepdt on a.assnmtIdPk = mrepdt.assnmtIdPk and ra.raCrtdDt = mrepdt.MaxRepDate group by s.stat">
</asp:SqlDataSource>
Here's the RadHtmlChart:
<telerik:RadHtmlChart runat="server" ID="rhc_assnmtStats" Transitions="true" Skin="Default" DataSourceID="sdsAssnmtStats" >
<PlotArea>
<Series>
<telerik:PieSeries StartAngle="90">
<LabelsAppearance Position="OutsideEnd"></LabelsAppearance>
<SeriesItems>
<telerik:PieSeriesItem Exploded="true" Name="stat" Visible="true" VisibleInLegend="true" Y="StatCount" />
</SeriesItems>
</telerik:PieSeries>
</Series>
</PlotArea>
<Legend>
<Appearance Position="Right" Visible="true"></Appearance>
</Legend>
<ChartTitle Text="Assignment Counts by Status">
<Appearance Align="Center" Position="Top"></Appearance>
</ChartTitle>
</telerik:RadHtmlChart>
Here's the asp:Chart markup I used that works as expected:
<asp:Chart ID="assnmtStats" runat="server" DataSourceID="sdsAssnmtStats">
<Titles>
<asp:Title Font="Times New Roman, 14pt, style=Bold, Italic" Name="AssnmtStatsTitle" Text="Assignment Counts by Status"></asp:Title>
</Titles>
<Series>
<asp:Series Name="Series1" ChartType="Pie" XValueMember="stat" YValueMembers="StatCount" YValueType="Int32" Legend="assnmtStatsLegend" IsValueShownAsLabel="true"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="assnmtStatsChartArea" Area3DStyle-Enable3D="true"></asp:ChartArea>
</ChartAreas>
<Legends>
<asp:Legend Name="assnmtStatsLegend" Alignment="Center"></asp:Legend>
</Legends>
</asp:Chart>
What do I need to do to get the RadHtmlChart to work?
This is an ASP.net C# WebForms application I'm creating in Visual Studio 2017.

I received a solution from Telerik. I hope this helps anybody else who has trouble translating the demo on their site from a bar chart to a pie chart.
When data binding the chart series you need to set its DataFieldY property to point to the field name you want to use instead of populating its SeriesItems collection.
Here's the working solution:
<telerik:RadHtmlChart runat="server" ID="rhc_assnmtStats" Transitions="true" Skin="Default" DataSourceID="sdsAssnmtStats" >
<PlotArea>
<Series>
<telerik:PieSeries StartAngle="90" NameField="stat" DataFieldY="StatCount">
<LabelsAppearance Position="OutsideEnd"></LabelsAppearance>
</telerik:PieSeries>
</Series>
</PlotArea>
<Legend>
<Appearance Position="Right" Visible="true"></Appearance>
</Legend>
<ChartTitle Text="Assignment Counts by Status">
<Appearance Align="Center" Position="Top"></Appearance>
</ChartTitle>
</telerik:RadHtmlChart>

Related

Adding a text area in table and saving it to SQL Server database

I'm using Classic ASP to add a note function to the table that is displaying rows from a database. The inserted row will save to the database saved Remarks but the following code isn't working.
<%
Dim fRemark
fRemark = Request.Form("Remarks")
Dim rsIntra,MyQryItr2
set cnIntra = Server.CreateObject("ADODB.Connection")
set MyQryItra2 = server.CreateObject ("ADODB.Recordset")
set rsIntra = Server.CreateObject("ADODB.Recordset")
MyQryItra2 = "select Remarks from [PurchaseOrderTrackInfo]"
rsIntra.Open MyQryItra,strRMSIDMcn
if rsIntra.eof then
MyQryItr2 = "insert into [PurchaseOrderTrackInfo] Remarks values N'" & fRemark & " '; "
cast(Remarks as int)
cnIntra.Execute MyQryItr2
else
rsIntra.close
set rsIntra = Nothing
set rsIntra = server.CreateObject("ADODB.Recordset")
MyQryItr2 = "UPDATE [PurchaseOrderTrackInfo] SET Remarks = N'" & fRemark & " '; where Remarks = rowID;"
end if
set rsIntra=Nothing
strConnDB= "Driver={SQL Server};Server=GB;Database=PurchaseOrderTrackInfo;UID=madfox;PWD=;"
%>
<td colspan="10" bordercolor=#3399ff bgcolor=#FFFF99 align="center">
<font face="Arabic Transparent" size="1" color="#800080"></font>
<form action=UpdatePO1.asp method=post >
<textarea name="Remarks" cols="20" rows="2" ><%=fRemark%></textarea>
<input type="submit" class="btn1" value="save" name="finish"/>
<input type="hidden" name="rowID" value="ID" />
</td>
</form>
<%
you never execute your update query. also your update statement does not seem to be valid as you are using the column Remarks as storage for the Remark and as row id. consider adding a rowid column to you table and use the following update statement
MyQryItr2 = "UPDATE [PurchaseOrderTrackInfo] SET Remarks = N'" & fRemark & " ' where rowId =" & rowID
cnIntra.Execute MyQryItr2
Since your code is vulnerabe to SQL injection, you should look up parameterized queries.

How to show sub categories under main category

I need some help on classic ASP.
Currently, the output shows like:
cat
south
cat
south
cat2
east
cat2
west
I don't want to see the main categories repeating like that.
How do I combine main category into one and show sub categories below main?
Like:
cat
south
south
cat2
east
west
Category table
ID Category
------------
01 cat
02 cat2
03 cat3
Subcat table
ID Subcat Category_id
-------------------------
1 south 01
2 north 01
3 east 02
4 west 02
5 line 03
Code:
<%
sSQL = " SELECT s.*, c.* FROM Category c, Subcat s WHERE s.Subcat_id = c.Subcat_id "
objRS.Open sSQL, objCon
response.Write sSQL
Do Until objRS.EOF
sCategory = objRS("Category")
sSubcat = objRS("Subcat")
%>
<input type="text" name="CategoryN" size="40" maxlength="50" value="<%= sCategory %>"><br />
<input type="text" name="SubcatN" size="40" maxlength="50" value="<%= sSubcat %>"><br />
<%
objRS.MoveNext
Loop
objRS.Close
%>
Thanks very much!
Something like this:
<%
currCat = "~~~~~~"
sSQL = "SELECT s.*, c.* FROM Category c, Subcat s WHERE s.Subcat_id = c.Subcat_id "
objRS.Open sSQL, objCon
response.Write sSQL
Do Until objRS.EOF
sCategory = objRS("Category")
sSubcat = objRS("Subcat")
if currCat <> sCategory Then
currCat = sCategory
<%
<input type="text" name="CategoryN" size="40"
maxlength="50" value="<%=sCategory%>"><br />
%>
End If
%>
<input type="text" name="SubcatN" size="40"
maxlength="50" value="<%= sSubcat %>"><br />
<%
objRS.MoveNext
Loop
objRS.Close
%>

How to get item from DataList

I have the following in an ascx file:
<asp:DataList ID="dtlTabs" runat="server" RepeatDirection="Horizontal" EnableViewState="False" CellPadding="0">
<ItemTemplate>
<asp:HyperLink ID="hlTab" NavigateUrl='<%# Eval("Url")%>' Tag='<%# Eval("Key") %>' Text='<%# Eval("Title") %>' runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:DataList>
Instead of iterating through it as a datalist, can I print only Title of item 3 ? I'm not sure how to pick just one item from the dtlTabs and print it.
Got it:
Dim dt As Data.DataSet = DirectCast(dtlTabs.DataSource, Data.DataSet) ' Cast the datasource back into a dataset
Dim dr As Data.DataRow = dt.Tables(0).Rows(4) ' Take the fourth row from the first table
Response.Write(dr("Title")) ' Output the text

PowerShell's Sort-Object cmdlet changing the order w.r.t. attributes not sorted on

I'm sorting some XML and would like to sort elements based on a particular, non-unique attribute, which allows me to group like-elements. Within these groups, I need to keep the original ordering. The problem is that when sorting, the order inside these groups changes and when re-sorting then the order changes yet again. I need a sort that doesn't change things if the content of the XML hasn't changed (otherwise SVN diffs are ugly). Here is a simplified example:
$xml = [xml]#"
<root>
<element name="a" number="1" />
<element name="b" number="1" />
<element name="c" number="1" />
<element name="d" number="2" />
<element name="e" number="2" />
<element name="f" number="2" />
<element name="g" number="3" />
<element name="h" number="3" />
</root>
"#
Write-Host "`nFirst Sort produces this:"
$result1 = $xml.SelectNodes('//element') | Sort-Object -Property 'number'
Write-Host (($result1 | select -ExpandProperty 'number') + " <---Sorted on")
Write-Host (($result1 | select -ExpandProperty 'name') + " <---Order not maintained")
Write-Host "`nSorting the (already sorted) results of First Sort produces this:"
$result2 = $result1 | Sort-Object -Property 'number'
Write-Host (($result2 | select -ExpandProperty 'number') + " <---Sorted on")
Write-Host (($result2 | select -ExpandProperty 'name') + " <---Order changed again")
Here is the output:
First Sort produces this:
1 1 1 2 2 2 3 3 <---Sorted on
c b a f e d h g <---Order not maintained
Sorting the (already sorted) results of First Sort produces this:
1 1 1 2 2 2 3 3 <---Sorted on
a b c d e f g h <---Order changed again
In this example, I need to preserve the original "name" ordering within the "number groups".
Can anyone think of an easy way to make this maintain the original order and come out the same when sorting multiple times?
I'm trying to avoid adding dummy attributes representing the original ordering. Maybe there is a different .NET sorting function that's more deterministic? I searched but nobody seemed to be concerned with ordering within equivalent groups.
Thanks.
If you don't have something that already represents the natural sort order, you can just add an index property with Add-Member:
$nodes = #($xml.SelectNodes('//element'))
for ($i=0; $i -lt $nodes.Count; $i++)
{
$nodes[$i] = $nodes[$i] | Add-Member -MemberType NoteProperty "Index" $i -PassThru
}
$result1 = $nodes | Sort-Object name, Index
Then you are guaranteed to get the same ordering no matter how many times you re-sort.
Update: added syntax for PowerShell v2
Sort with respect to both the properties:
$xml.SelectNodes('//element') | Sort-Object -Property number, name
This produces this output:
name number
---- ------
a 1
b 1
c 1
d 2
e 2
f 2
g 3
h 3

Colfdfusion loop status update Ajax

I have a loop in Coldfusion which will run for a long time; about 2-4 minutes.
I would like to show a status update every time the loop has ran.
The loop:
<cfloop index="i" from=1 to=70>
<cfset allHtmlFiles=getThirdXml.XmlRoot.XmlChildren[i].XmlChildren[1].XmlText>
<cfset ArrayAppend(seekurl, allHtmlFiles)>
</cfloop>
The loop which takes care of showing data:
<cfloop index="loopcount" from=1 to=92>
<cfset checkThisUrl = #seekurl[loopcount]#>
<cfset completeUrl ="http://myurl.com/?ids=#checkThisUrl#">
<cfhttp result="get" method="get" url="#completeUrl#">
<cfset nieuw =deserializeJSON( get.filecontent )>
<cfoutput>
<tr>
<cfif nieuw[checkThisUrl].id IS NOT 0>
<td>#nieuw[checkThisUrl].id#</td>
</cfif>
<cfif isDefined("nieuw[checkThisUrl].shares")>
<td style="text-align: right">#nieuw[checkThisUrl].shares#</td>
</cfif>
</tr>
</cfoutput>
</cfloop>
How can I accomplish the Ajax update on every run?
The way I would so this is write the progress so far with a unique ID (like a UUID) to the database. Then you can use AJAX to poll through a different script to get the progress of the script.
The database table might look like this:
InsertedOn | Data | UUID
2011-02-12 13:01 | MyProcessData1 | MyUUID1
2011-02-12 13:02 | MyProcessData2 | MyUUID1
2011-02-12 13:03 | MyProcessData3 | MyUUID1
2011-02-12 13:10 | MyProcessData1 | MyUUID2
2011-02-12 13:11 | MyProcessData2 | MyUUID2
2011-02-12 13:12 | MyProcessData3 | MyUUID2
For example:
Kick off the process described above with an AJAX request. The request will start the code above as a thread (so it returns immediately) and return a UUID value representing the request
The process described above will write the progress to a database table with the UUID for each entry
Poll using a different script using AJAX every few seconds using the UUID value to find the progress so far
Perhaps there are other ways however!
Hope it helps.
Ciaran

Resources