Search code examples
coldfusionpie-chartcfchart

ColdFusion : How to link each part of a pie chart to a specific URL?


I've got a basic pie chart with values like this

    <cfchartdata item="January" value="503100">
    <cfchartdata item="February" value="720310">
    <cfchartdata item="March" value="688700">

I'd like to link each piece of the pie to a specific URL - I don't need to post any variables to the URL.

I tried something like this;

<cfchartdata item="January" value="503100" url="januarydata.cfm">

but URL is not a valid attribute for 'cfchartdata'


Solution

  • The url attribute belongs to the CFChart tag, not the CFChartData tag

    URL:

    URL to open if the user clicks item in a data series; the onClick destination page.

    You can specify variables within the URL string; ColdFusion passes current values of the variables.

    • $VALUE$: the value of the selected row. If none, the value is an empty string.

    • $ITEMLABEL$: the label of the selected item. If none, the value is an empty string.

    • $SERIESLABEL$: the label of the selected series.

    • If none, the value is an empty string, for example: "somepage.cfm?item=$ITEMLABEL$&series=$SERIESLABEL$&value=$VALUE$

    • "javascript:...": executes a client-side script.

    if you want to do a dynamic search you can use the dynamic values above mixed in with static and other CF values. for example:

    <cfchart url="someSearchPage.cfm?param1=Static Text&param2=#form.ColdFusionFormVariable#&param3=$ITEMLABEL$" ...>
    

    In this example the $ITEMLABEL$ is converted to the label automatically.

    Disclaimer


    Before answering your actual question, I should point out that this isn't a good practice and defeats the entire purpose of a dynamic website. You should consider a single page that accepts a parameter and pulls the data from a database depending on that parameter. For example monthlyData.cfm?month=january


    The simplest way would be to put the item label in the file name as you confirmed worked in the comments.

    <cfchart url = "$itemLabel$data.cfm" ...>
    

    If you needed to do a little more testing before sending the user along, you could send them to a single ColdFusion page and use CFSWITCH / CFCASE or good old CFIF / CFELSE if there aren't that many combinations.

    -or-

    you could use the javaScript: option and run a function that uses window.location depending on the series clicked.

    javaScript:goto($itemSeries$,$seriesLabel$)
    

    The js function may look like:

    function goto(item,label){
      if(item == "..." && label== "..."){
       document.location = "..."; 
      }else{
       etc...;
      }
    }