Skip to main content

Like No Other

APEX pie charts allow you to limit the number of records that are displayed in the chart. This can be controlled by editing the Series and setting the Maximum Rows parameter. However, APEX will automatically add an "Other" slice to your chart, which represents all of the other data from the query. Consider this example: you have 10 different widget types, and 10 of each type for a total of 100 units. Here's some SQL to quickly create this scenario, if you want to follow along:
CREATE TABLE widgets (widget_type VARCHAR2(10))
/

DECLARE
  z NUMBER := 1;
BEGIN
FOR y IN 1..10
LOOP
  FOR x IN 1..10
  LOOP
    INSERT INTO widgets VALUES ('Type ' || z);
    z := z + 1;
  END LOOP;
  z := 1;
END LOOP;
END;
/
If you wanted to sum them based on type and just see the first five types, you can use a simple SQL statement like this:
SELECT 
  NULL link,
  widget_type label, 
  COUNT(*) value
FROM 
  widgets
GROUP BY 
  widget_type 
ORDER BY 2
Which will in turn, produce a chart that looks like this: SafariScreenSnapz001 Clearly, not what you may expected, as you only wanted to see the top 5 widgets, not the top 5 plus all additional records grouped into an "other" slice. Visually, this may be misleading to the user. To get just the top 5 records, we have to use an inline SQL statement that will select from our original SQL statement and limit the results to just 5 records:
SELECT
  link,
  label,
  value
FROM
  (
  SELECT 
    NULL link,
    widget_type label, 
    COUNT(*) value
  FROM 
    widgets
  GROUP BY 
    widget_type 
  ORDER BY 2
  )
WHERE
  rownum < 6
With this approach, we let APEX create the chart and append the Other slice to the results. We then siphon off just the first five records, which in this case, will not include the Other slice. The result is something closer to what many users would expect: SafariScreenSnapz002 Using this approach, the value of the Maximum Rows can be set anything greater than or equal to the value compared to ROWNUM in the last line of the second SQL statement, as we will be using the WHERE clause to limit how many records are displayed.

Comments

jts194 said…
Scott,
We're using APEX 4.1 and APEX Listener 1.1.3. Have you ever had a problem with stored procedures parameter/signature caching. For example, if I create a stored procedure with two parameters (default null), I can access via browser through /apex/schema_name.procedure_name?p_one=1&p_tw0=2. Now, if I had a third parameter and change my URL signature to p_one=1&p_tw0=2&p_three=3, p_three is always null. Whenever the procedure is created or accessed, it seems its caching the signature and not acknowledging the new parameters. Any insight would be appreciated. Thanks
Josh S.
Scott said…
Josh,

Not sure how this comment relates to this post.

- Scott -

Popular posts from this blog

Whose Deck is it Anyways?

This year at KScope, we're going to try something new.  And fun.  And funny to watch - we hope.  It's called "Whose Deck is it Anyways?", and will occur on Sunday at 8:30pm.  It's only 30 minutes, but it will likely be the best 30 minutes of the conference.  Or at least the most embarrassing.

Here's what we're going to do: the will be four 5-minute presentations - one on each of the following: BI, EPM, Database & APEX.

Sound interesting?  Probably not.  We get that, too.  So here's what we did.

Each 5-minute session will be presented by a non-expert.  For example, it's highly likely that I'll be presenting on BI or EPM.

To make it even better, each slide deck will be prepared by the corresponding expert.  So again, it's highly likely that my slide deck's creator will be either Stewart Bryson or Edward Roske.  If nothing else, this session will be a crash course in how not to make cohesive, easy to read slides.

Interested now?  Ya,…

Spaced Out

A while back, I wrote about how to give the Universal Theme a face lift.  If you follow the steps in that post, the base font for an APEX application with the Universal Theme can easily be changed.

While that's all well and good, sometimes you only want to change the font for a report, not the entire page.  One of the applications that I'm building contains a number of IRs based mostly on log data.  Thus, having that data in a monospaced font would make it a whole lot easier to read.

You can search Google Fonts for monospaced fonts by selecting only that option on the right-side menubar.  You can also opt for the standard yet kinda boring Courier and achieve the same thing.

To implement this in your application, follow the steps in my other post, but stop shy of the final step.  Instead of pasting in the text that I specify, paste in the following to the Custom CSS field in Theme Roller, using the name of the font you selected for the font-family:

.a-IRR-table tr td { font-fam…

#fakecode

Unless you've managed to somehow filter out everything about US politics over the last few months (and if you have, please let me know your secret), then you've likely heard about "fake news".  From a high level, my basic understanding of "fake news" is that it refers to stories or websites that are fabricated to advance the political beliefs and/or ideologies of one site or the other.  Your definition may differ.

So what is fake code?  That, I can at least try to explain in a bit more detail.

The other day, I saw this image posted on Kris Rice's twitter feed:



I thought it was a joke, but it's actually a real book. That made me laugh.  Then cry.  Then I read the book, mainly since it's only 4 pages.  Believe it or not,  there's actually some really good content packed in there.  Let me summarize:

If you choose to copy code from Stack Overflow, the OTN forum, or anywhere, really, there's a few things to keep in mind:


Who owns the code.  It…