Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: Dynamically Set Series Titles for Chart

  1. #1
    Join Date
    Jun 2013
    Posts
    4

    Default Dynamically Set Series Titles for Chart

    Hi,

    I am relatively new to the CTools suite and am struggling to solve the following issue.

    Our dashboard includes several charts that use a common Kettle transformation to return two sets of data to display as two lines in a simple line chart. The problem is that we don't know what each of the series titles should be in advance and need to set these dynamically somewhere in the process.

    The current chart is shown below

    Name:  CCC Dashboard Image.jpg
Views: 149
Size:  14.8 KB

    I would like to be able to set the labels shown as metric1 and metric1_1 dynamically based on parameters that are set in the dashboard. E.g. chart1Series1Label, chart1Series2Label, etc.

    What is the best way of achieving this?

    Any help is greatly appreciated.

    Best

    Rod

  2. #2
    Join Date
    Jul 2007
    Posts
    2,497

    Default

    You can change the title of the metadata in the postFetch property of the query
    Pedro Alves
    Meet us on ##pentaho, a FreeNode irc channel

  3. #3
    Join Date
    Jun 2013
    Posts
    4

    Default

    Hi Pedro,

    Thanks for your reply. Could you provide a short example?

  4. #4
    Join Date
    Mar 2012
    Posts
    645

    Default

    Suppose your data is in cross-tab format.
    The first data column will be the category (days of the month, as it looks by your example).
    The second data column will be "metric1" and the third "metric1_1".

    The way @pmalves is saying is, in your postFetch handler:

    Code:
    function f(cdaData) {
      var metadata = cdaData.metadata
      metadata[1].title = Dashboards.getParameterValue("chart1Series1Label");
      metadata[2].title = Dashboards.getParameterValue("chart1Series2Label");
    
      return cdaData;
    }
    That's it - simple. If your data is in relational format, you'll need to do a little more gymnastic.

    If, however, you're using CCCv2, there's one advantage of doing it through the "dimensions" chart option - it doesn't depend on the source data table format:
    Code:
    function f(cdaData) {
    
      this.chartDefinition.dimensions = {
         series: {
            formatter: function(v) {
              switch(v) {
                 case 'metric1':   return Dashboards.getParameterValue("chart1Series1Label");
                 case 'metric1_1': return Dashboards.getParameterValue("chart1Series2Label");
              }
              return String(v);
            }
         }
      };
    
      return cdaData;
    }
    The later can also be done in the preExecution handler (although postFetch is almost always a better option - it works in CGG as well).
    Last edited by duarte.leao; 06-11-2013 at 07:57 AM.

  5. #5
    Join Date
    Jun 2013
    Posts
    4

    Default

    Many thanks Duarte & Pedro, greatly appreciated.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.