WillM

Usage of Variables as Chart Labels

Recommended Posts

Hello, I have the following column chart that is designed to show the four most popular books in the last month taken out of a library. As you can see the labels of each column are $bookPos1-4. These variables are from an array that checks to see which books are the most popular.

Untitled.png.9aa2c1f613cad8c359934d5e0da5ba25.png

The variables will need updating every time the page is loaded. Using the following code to wire up the chart, I have no luck. If the variables are unquoted it simply reverts to the previous labels/blank. The code used is copied from the example and adapted slightly.

$bookChart = new FusionCharts("column2d", "book", "100%", 150, "topFourChartBox", "json", '{  
                              "chart":{  
                                "caption":"Top Four Titles",
                                "subCaption":"The most popular books in the last month.",
                                "numberPrefix":"",
                                "theme":"carbon"
                              },
                              "data":[  
                                {  
                                  "label":"$bookPos1",
                                  "value":"100"
                                },
                                {  
                                  "label":"$bookPos2",
                                  "value":"90"
                                },
                                {  
                                  "label":"$bookPos3",
                                  "value":"50"
                                },
                                {  
                                  "label":"$bookPos4",
                                  "value":"20"
                                }
                              ]
                             }');
// Render the chart
$bookChart->render();

Thanks for the help! :D

Share this post


Link to post
Share on other sites

SOLVED

$bookChart = new FusionCharts("column2d", "book", "100%", 150, "topFourChartBox", "json", '{  
                              "chart":{  
                                "caption":"Top Four Titles",
                                "subCaption":"The most popular books in the last month.",
                                "numberPrefix":"",
                                "theme":"carbon"
                              },
                              "data":[  
                                {  
                                  "label":"'.$bookPos1.'",
                                  "value":"100"
                                },
                                {  
                                  "label":"'.$bookPos2.'",
                                  "value":"90"
                                },
                                {  
                                  "label":"'.$bookPos3.'",
                                  "value":"50"
                                },
                                {  
                                  "label":"'.$bookPos4.'",
                                  "value":"20"
                                }
                              ]
                            }');

// Render the chart
$bookChart->render();

Broke the string and used the '.' operate to connect in my variables.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now