{"id":83,"date":"2010-04-16T17:50:00","date_gmt":"2010-04-16T17:50:00","guid":{"rendered":"\/lisa\/post\/2010\/04\/16\/YAPS-on-Dynamic-Reports-and-Parameters-Charts-get-into-the-act.aspx"},"modified":"2010-04-16T17:50:00","modified_gmt":"2010-04-16T17:50:00","slug":"yaps-on-dynamic-reports-and-parameters-charts-get-into-the-act","status":"publish","type":"post","link":"https:\/\/spacefold.com\/lisa\/2010\/04\/16\/yaps-on-dynamic-reports-and-parameters-charts-get-into-the-act\/","title":{"rendered":"YAPS on Dynamic Reports and Parameters: Charts get into the act"},"content":{"rendered":"<p>Wow.&nbsp;I can&#8217;t believe how long it&#8217;s been since my last post here.<\/p>\n<p>The questions are piling up, the garden wants attention, or at least serious admiration, and I&#8217;m travelling a bit more than I&#8217;d like for work. C and I keep stockpiling films we&#8217;d like to see&#8230; someday. And&nbsp;time really flies when you have a <a title=\"blog post about the perfect grandchild\" href=\"\/lisa\/2009\/08\/14\/And-then-there-were-three\/\">Jonah<\/a>&nbsp;to play with.<\/p>\n<p>It&#8217;s getting more and more difficult to find time to sift through the compost, let alone the interesting requests for help that I get here.<\/p>\n<p>Before getting on the next plane and making the next meeting, I&#8217;d like to answer at least one item of general interest, and it shouldn&#8217;t take long. I&#8217;ll give you the entire question in a short, separate text file, with no attribution, because there are some ins and outs that are not entirely relevant, and the question unfolded over several messages.<\/p>\n<p><a href=\"\/lisa\/wp-non\/migrated\/2010\/4\/DynamicChartExpressionsQuestion.txt\" target=\"_blank\" rel=\"noopener\">DynamicChartExpressionsQuestion<\/a><\/p>\n<p>In general, here are the requirements&nbsp; we have:<\/p>\n<ul>\n<li>Do something the same way in WebForm and WinForm.&nbsp; Well, ReportViewer certainly fits that bill. But the full question indicates that the person doesn&#8217;t necessarily know that &#8212; so I&#8217;d better mention it.<\/li>\n<li>Do it with an RDLC. No problem there, in either environment.<\/li>\n<li>Show a&nbsp;scatterplot several times on a page, each time using different columns of the same dataset for the axes, and potentially other aspects of the graph, such as titles.<\/li>\n<\/ul>\n<p>The request also specifies that the graphs are simple plots, nothing fancy, so I&#8217;m not going to worry much about the details of formatting a scatterplot.<\/p>\n<p>In general, it&#8217;s the dynamic&nbsp;data aspects that seem to be the issue.&nbsp; I&#8217;ll excerpt: <em>&#8220;I can deal with the looping to add the graphs but the bit I can&#8217;t get my head around is how to programmatically specify the x and y data source and also the axis titles using the headings. All my graphs will be the same layout and format so I can use a single rdlc file for that.&#8221;<\/em>&nbsp;<\/p>\n<h3>This question will remain anonymous<\/h3>\n<p>I usually name the questioner, but in this case, he mentioned one detail&nbsp;about his work situation I&#8217;d like to share without causing him any work difficulties: for whatever reason, he&#8217;s been stuck in VS and RS 2005.&nbsp; So that&#8217;s what I&#8217;m going to use to illustrate, although I&#8217;m sure it&#8217;s pretty much the same scenario in later versions.&nbsp; (At least I hope it is &#8212;<a title=\"blog post about RS versionitis\" href=\"\/lisa\/2010\/02\/20\/YAPS-on-Dynamic-PageBreaks-the-RS-2005-SQL-Sequel\/\"> I&#8217;ve been wrong before<\/a>, please let me know if this is a technique that needs to be tweaked.&nbsp; Certainly charting changed a lot in RS 2008.)<\/p>\n<p class=\"NB\">I especially want to mention this version constraint because I&#8217;m seeing the same thing&nbsp;with a number of clients.&nbsp; For whatever reason &#8212; hosted databases on a third-party provider, generally conservative habits, a huge backload of work that would need testing for a new version &#8212; a lot of people are just beginning to move towards SQL Server 2008 now.&nbsp; It makes it difficult for me to get really excited about 2010 and all the truly gotta-have improvements it &#8220;must&#8221; be bringing.&nbsp; I guess I&#8217;m just getting old.<\/p>\n<p>Now, about that question.<\/p>\n<h3>Simple setup<\/h3>\n<p>To simplify my own life, I&#8217;m going to fake the situation using a table from my usual SQLWorld database, with some random values in three columns (don&#8217;t try to make sense of this data) that I&#8217;ll specify dynamically for one axis.&nbsp; I&#8217;m sure you&#8217;ll see how this could be extended to the other axis.&nbsp; I&#8217;ll also dynamically determine the axis title using the name of the column I&#8217;m dynamically specifying, rather than considering this a separate problem, since we know this is different for each iteration of the graph.&nbsp; <\/p>\n<p><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">SELECT<\/span><\/span><span style=\"font-size: x-small;\"> <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">TOP<\/span><\/span><span style=\"font-size: x-small;\"> 25 <br \/><\/span><span style=\"color: #ff00ff; font-size: x-small;\"><span style=\"color: #ff00ff; font-size: x-small;\">&nbsp;&nbsp; RTRIM<\/span><\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">(<\/span><\/span><span style=\"font-size: x-small;\">Country<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">.<\/span><\/span><span style=\"font-size: x-small;\">Name<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">)<\/span><\/span><span style=\"font-size: x-small;\"> <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">AS<\/span><\/span><span style=\"font-size: x-small;\"> Country <\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">,<br \/><\/span><\/span><span style=\"color: #ff00ff; font-size: x-small;\"><span style=\"color: #ff00ff; font-size: x-small;\">&nbsp;&nbsp; ROW_NUMBER<\/span><\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">()<\/span><\/span><span style=\"font-size: x-small;\"> <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">OVER<\/span><\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">(<\/span><\/span><span style=\"font-size: x-small;\"> <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">ORDER<\/span><\/span><span style=\"font-size: x-small;\"> <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">BY<\/span><\/span><span style=\"font-size: x-small;\"> Country<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">.<\/span><\/span><span style=\"font-size: x-small;\">Name<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">)<\/span><\/span><span style=\"font-size: x-small;\"> <\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">%<\/span><\/span><span style=\"font-size: x-small;\"> 5 <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">AS<\/span><\/span><span style=\"font-size: x-small;\"> <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">Sets<\/span><\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">,<br \/><\/span><\/span><span style=\"color: #ff00ff; font-size: x-small;\"><span style=\"color: #ff00ff; font-size: x-small;\">&nbsp;&nbsp; SUM<\/span><\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">(<\/span><\/span><span style=\"font-size: x-small;\">City<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">.<\/span><\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">Population<\/span><\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">)<\/span><\/span><span style=\"font-size: x-small;\"> <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">AS<\/span><\/span><span style=\"font-size: x-small;\"> RandomX1<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">,<br \/><\/span><\/span><span style=\"color: #ff00ff; font-size: x-small;\"><span style=\"color: #ff00ff; font-size: x-small;\">&nbsp;&nbsp; MIN<\/span><\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">(<\/span><\/span><span style=\"font-size: x-small;\">City<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">.<\/span><\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">Population<\/span><\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">)<\/span><\/span><span style=\"font-size: x-small;\"> <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">AS<\/span><\/span><span style=\"font-size: x-small;\"> RandomX2<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">,<br \/><\/span><\/span><span style=\"color: #ff00ff; font-size: x-small;\"><span style=\"color: #ff00ff; font-size: x-small;\">&nbsp;&nbsp; MAX<\/span><\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">(<\/span><\/span><span style=\"font-size: x-small;\">City<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">.<\/span><\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">Population<\/span><\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">)<\/span><\/span><span style=\"font-size: x-small;\"> <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">AS<\/span><\/span><span style=\"font-size: x-small;\"> RandomX3<br \/><\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">FROM<br \/><\/span><\/span><span style=\"font-size: x-small;\">&nbsp;City <\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">JOIN<\/span><\/span><span style=\"font-size: x-small;\"> Country <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">on<\/span><\/span><span style=\"font-size: x-small;\"> City<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">.<\/span><\/span><span style=\"font-size: x-small;\">CountryCode <\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">=<\/span><\/span><span style=\"font-size: x-small;\"> Country<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">.<\/span><\/span><span style=\"font-size: x-small;\">Code<br \/><\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">GROUP&nbsp;<\/span><\/span><span style=\"font-size: x-small;\"> <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">BY<\/span><\/span><span style=\"font-size: x-small;\"> Country<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">.<\/span><\/span><span style=\"font-size: x-small;\">Name <br \/><\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">ORDER<\/span><\/span><span style=\"font-size: x-small;\"> <\/span><span style=\"color: #0000ff; font-size: x-small;\"><span style=\"color: #0000ff; font-size: x-small;\">BY<\/span><\/span><span style=\"font-size: x-small;\"> Country<\/span><span style=\"color: #808080; font-size: x-small;\"><span style=\"color: #808080; font-size: x-small;\">.<\/span><\/span><span style=\"font-size: x-small;\">Name<\/span><\/p>\n<p>If you&#8217;re playing along, just think &#8220;pivot table&#8221; in Excel and you&#8217;ll have the right-shaped data.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"TEXT-ALIGN: center\"><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/4\/DCE1-Data.PNG\" alt=\"\" \/><\/p>\n<p>To be honest, I think if I was solving this problem, I&#8217;d use a different data structure.&nbsp; I wouldn&#8217;t pivot the data, I&#8217;d use a key column to indicate what type of value each row was.&nbsp; Each graph would filter the results differently.&nbsp;<\/p>\n<p>But, if the graph is doing the filtering, rather than the dataset doing it before the RDLC &#8220;sees&#8221; the dataset, you&#8217;re still specifying something dynamically in the graph &#8212; and you&#8217;ll still be able to do it the way I&#8217;m showing you here.<\/p>\n<p>There&#8217;s nothing special about the layout, either:<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/4\/DCE2-Layout.PNG\" alt=\"\" \/><\/p>\n<h3>Specifying dynamic behavior to a graph<\/h3>\n<p>How do you normally give instructions to a report from the outside?&nbsp; You use a parameter, of course.&nbsp;<\/p>\n<p>It&#8217;s no different&nbsp;here.&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/4\/DCE3-Parameter.PNG\" alt=\"\" \/><\/p>\n<p class=\"NB\">As I write this, I&#8217;m wondering if the person asking the question doesn&#8217;t understand how to use parameters with an RDLC.&nbsp; If that&#8217;s the case, he&#8217;ll write and tell me, and I&#8217;ll explain (probably by pointing him to a <a title=\"blog post on dynamic use of RDLCs with simple parameter adjustment example\" href=\"\/lisa\/2007\/09\/19\/Dynamically-loading-reports-in-ReportViewers\/\">different post<\/a>).&nbsp;<\/p>\n<p>In this example, I&#8217;m going to use a single parameter, shown above, to provide&nbsp;information for one axis and also the chart title. I&#8217;ll use a direct expression for the former and a code function for the latter, just to illustrate the possibilities.&nbsp; Obviously, you can have additional parameters (and do more of the work outside the report, rather than writing a code function inside the report) if you want.<\/p>\n<p>As you can see here, the code function shows up in the Chart Properties&#8230;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/4\/DCE4-ChartProperties.PNG\" alt=\"\" \/><\/p>\n<p>&#8230; and the function itself is just for illustration purposes (it didn&#8217;t matter what I used here, as long as you could see that the result was dynamic)&#8230;<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/4\/DCE5-Code.PNG\" alt=\"\" \/><\/p>\n<p>Now we come to the axes.&nbsp; Forgive me for naming the columns incorrectly; by the time I whipped up the graph I&#8217;d decided to specify Y dynamically, instead of X (in real life, of course, you can do both), so I shouldn&#8217;t have named them RandomX&lt;N&gt;.&nbsp; The X axies is really being specified as Country in this example:<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/4\/DCE6-XAxes.PNG\" alt=\"\" \/><\/p>\n<p>&#8230; and, just to make sure you see everything, the Series in this graph are taken care of by the Sets column I added to the dataset:&nbsp;<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/4\/DCE7-Series.PNG\" alt=\"\" \/><\/p>\n<p>&#8230; which just leaves us with the dynamic column.&nbsp; It&#8217;s specified similarly to the other items you see above, by using an expression rather than a literal.&nbsp; You&#8217;ve already seen it in the layout above, but here it is up close and personal:<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/4\/DCE8-DynamicValues.PNG\" alt=\"\" \/><\/p>\n<p>&nbsp;&#8230; pretty much as you would expect.&nbsp; For each iteration of the loop, your code is&nbsp;going to change the value of WhichColumn to match one of your field names in the dataset, and this is going to drive your graph&#8230;<\/p>\n<table border=\"0\">\n<tbody>\n<tr>\n<td><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/4\/DCE9-Results.PNG\" alt=\"\" \/><\/td>\n<td valign=\"top\">\n<p>&#8230; and that&#8217;s all she wrote.&nbsp; If you have questions, or if there is a complexity I&#8217;m overlooking here, please let me know?<\/p>\n<h3>Hmmmm.<\/h3>\n<p>As I write this, I wonder if there is an obvious way to do this without iterating over the graphs in code that I&#8217;m not thinking about.<\/p>\n<p>Why, for example, can&#8217;t I use a code variable instead of a parameter here, and change the information in a function called between each graph?<\/p>\n<p>That approach could be dangerous &#8212; especially when we change versions &#8212; but I might be able to group on a sequencing SQL column to do the same thing, or something similar.<\/p>\n<p>And I still bet it would be easier without the&nbsp;table being pivotted, probably painfully, in preparation.<\/p>\n<h3>Hard to get to !?!<\/h3>\n<p>It bears thinking about. Maybe on the plane&#8230;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>P.S.<\/h3>\n<p>Yes I know that last line was a stretch, but I haven&#8217;t paid my <a title=\"Serenity the movie\" href=\"http:\/\/www.serenitymovie.com\/\" target=\"_blank\" rel=\"noopener\">Serenity tax<\/a> in a while.<\/p>\n<p>Wow, now, that&#8217;s a cheery link to visit just before a plane trip&#8230;<\/p>\n<p class=\"NB\">&#8220;This is the captain, we may experience some turbulance, and then&#8230; explode.&#8221;&nbsp; <br \/>&#8220;I don&#8217;t wanna explode!&#8221; <br \/>&#8220;I think we better run&#8230;&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wow.&nbsp;I can&#8217;t believe how long it&#8217;s been since my last post here. The questions are piling up, the garden wants attention, or at least serious admiration, and I&#8217;m travelling a bit more than I&#8217;d like for work. C and I keep stockpiling films we&#8217;d like to see&#8230; someday. And&nbsp;time really flies when you have a<a class=\"more-link\" href=\"https:\/\/spacefold.com\/lisa\/2010\/04\/16\/yaps-on-dynamic-reports-and-parameters-charts-get-into-the-act\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6,12],"tags":[],"class_list":["post-83","post","type-post","status-publish","format-standard","hentry","category-reporting","category-sql-server","category-yaps"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":0,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}