2

I have created a chart using Forena reports. I need to set the chart title dynamically based on the logged in user's country. At present I have hard coded the title as "Your Country". The data for this chart is coming from a data block (let's say data_block_1). And the logged in user's country can be obtained from a second data block(data_block_2).

How can I show the logged in user's country as the chart tile?

Though I have the second data block I don't know where to put the name or how to call that data block.

I am posting the screenshot of the body tag inside the frx file and also the chart I created thus and also the sql file.

enter image description here

enter image description here

enter image description here

2
  • Please EDIT your question to clarify this: (a) Is "Your Country" your current chart title you want to change to the user's country? (b) How do you have the data about "User's country" available in your Drupal site (or how do you retrieve that info somehow)? (c) Why does the title of your question include "multiple data blocks", while your report specification (FRX in XHTML fmt) you posted only includes 1 data block? (d) what's the relationship between the FRX image and the chart image you posted? Commented Nov 2, 2015 at 9:42
  • Thanks for adding all those details, it answers (a), (b) and (c) in my prior comment. But you didn't answer my (d) yet, can you do that to please? Also, in your FRX I do not SEE the "Your Country" (only "Logged in user's country"). Is it OK to assume that apart from that variation the FRX and chart image actually match? Can you clarify these remaining details please? Commented Nov 2, 2015 at 10:10

1 Answer 1

0

Using data contexts

This question is a (great) example of using "Data contexts" in Forena. To see an example of a "data context" at work (in a demo site), refer to the example about Master Summary with drill down. If in the report you click any of the linked columns (such as for state = VA), you'll get the Users in state Virginia report. In that report you should note these things:

  • ... in state Virginia (in the report title).
  • ... state with code = VA (near the top of the report).

If in the above example you pick another state, such as IL (Illinois), you'll get the report specific to that state.

Read more about "Data Contexts" in the Forena documentation, which you can also find in your own site within /reports/help.reportingfrx#datacontexts (after you installed Forena).

Below are some details about what's needed in this specific case (to use the user's country as your chart tile), based on these assumptions:

  • The user's country is contained in stored in a datablock named (say) "pec_reports/data_block2", within a column (say) "UserCountry".
  • The user's country is (say) "XYZ".
  • You want your chart title to be like (say) "Chart for country XYZ".

Based on these assumptions, this is what you should do:

  1. Add a data context to the document in the section of the document, which are preloaded before the report is rendered. The example below illustrates the syntax for preloading data in the head section:

    <head>
      ..
      <frx:data id="countryinfo" block="pec_reports/data_block2"/>
    </head>
    
  2. Any data from any other section of a report may be used by referencing the datablock by its id and appropriate column name of that datablock. The example below contains an example of referencing the UserCountry column contained in pec_reports/data_block2:

    <div> ... {countryinfo.UserCountry} ... </div>
    

    The syntax for such reference is like so:

    • "Id" of the datablock, followed by a ".", and followed by the "ColumnName".
    • Preceeded by a "{" and followed by "}".
  3. Same is true for any of the tags used to specify the details of the chart you want to create. So in this case you could use something like so:

    frx:graph_title="{countryinfo.UserCountry}"
    

Ensure your SQL returns the correct value(s)

If you get a blank chart title after applying the changes as I suggested above, then most probably that is because the value of that chart title is blank. Looking at the SQL statement for your pec_reports/data_block2, here are a few tips to further verify (debug?) the actual SQL statement you're using:

  1. Create a temporary (for debugging purposes only) tabular report using that same pec_reports/data_block2 data block, and run that report while logged in. Or as a variation, add that tabular report in your report with the chart, but in front of that chart. Do you get the expected "country" value for that user? I wouldn't be surprised if you get an empty output (which would confirm something is wrong in your SQL statement, and hence also explain your blank chart title). In that case continue with step "2." and/or "3." below.
  2. In your from clause, change users to {users}, and rerun your temporary report in step 1.
  3. In your where clause, change current_user to the value of the uid of your own user, and rerun your temporary report in step 1.

If none of the above seems to help, then I would use either (or both) of these other routes:

  • Have a look at the data blocks (SQL statements) related to the Drupal Administration reports that are delivered with Forena also, such as:

    • Active Users
    • Logs for User
    • Role Details
  • Use the query writing tool that comes with Forena, which is called the Forena Query Builder. This is a separated module that comes with Forena. It can be enabled as per standard Drupal instructions to enable an additional module. For a video tutorial about this query writing tool, checkout Define data blocks with optional filters.

6
  • It didn't work. Nothing is being shown on the graph. All I can see is a blank space. When I try to add a text, it's coming. But when I try to show the value from the block, it's not working.
    – vipin p
    Commented Nov 5, 2015 at 12:48
  • Sorry to hear that. Can you UPDATE the screenprint in your question to replace it with the entire content of your FRX file? Make sure it matches with the chart screenprint, e.g. its title (which as I wrote before doesn't seem to match ...). If possible also add the SQL statement of your data_block2 (there may be more straight forward solutions in your case). Commented Nov 5, 2015 at 12:56
  • I created a new report using the 2nd data block. And selected "simple table" format and it returned the country name of the logged in user. So I think the query is working fine.
    – vipin p
    Commented Nov 5, 2015 at 14:18
  • Thank for confirming that part. But to me that's not sufficient as a "proof" that your current query is OK to also use it in the "context" as I explained in my answer. Have you tried my "Tip 2." already? If so, what result do you get then? Extra hint: "merging" the new report in front of the chart is maybe an acceptable work around (the country would be shown as a title BEFORE the chart, instead of title OF the chart) ... Commented Nov 5, 2015 at 14:37
  • I already tried the 2nd and 3rd options you mentioned. Both options failed. also I tried to show the name as a text field inside a div before the graph, But that didn't work either.
    – vipin p
    Commented Nov 5, 2015 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.