Error switching from simple table to VertGraph

Recently, i started developing my first piwik plugin, which displays data (currenlty unique visitors only) for weekdays. In the current state it works quite well, except the data can only be display on a simple table. However, i have no idea why it is not working as VertGraph. I compared my code with some other plugins, but found no greater differences, but the kind the figures are fetched. While the other plugins generate the archive directly i use the Visits Summary API and bring it together in the DataTable. Do i do something wrong?

Error message and code snippet below.

Open Flash Chart

JSON Parse Error [Syntax Error]
Error at character 1, line 2:

0: 1:

Warning: Division by zero in /My/Parh/To/Piwik/core/Visualization/Chart/VerticalBar.php on line 65

protected function getDataTable($name, $idSite, $period, $date )
    {
        Piwik::checkUserHasViewAccess( $idSite );
        $date = Piwik_Date::factory($date);
        $dataTable = new Piwik_DataTable();

        $weekdayKey = 'Weekday';
        $visitorKey = 'Unique Visitors';
        $idx = 'RowIndex';
        $uniqueVisitors = array(array($idx => 0, $weekdayKey => 'Mon', $visitorKey =>    0),
                                array($idx => 1, $weekdayKey => 'Tue', $visitorKey =>    0),
                                array($idx => 2, $weekdayKey => 'Wed', $visitorKey =>    0),
                                array($idx => 3, $weekdayKey => 'Thu', $visitorKey =>    0),
                                array($idx => 4, $weekdayKey => 'Fri', $visitorKey =>    0),
                                array($idx => 5, $weekdayKey => 'Sat', $visitorKey =>    0),
                                array($idx => 6, $weekdayKey => 'Sun', $visitorKey =>    0),
                                );

        $requestStringTemplate = 'method=VisitsSummary.getUniqueVisitors&idSite=' . $idSite . '&date={DATE}&period=day&format=original';

        switch ($period)
        {
            case 'year':
                $weeks = 52;
                break;
            
            case 'day':
            case 'week':
                $weeks = 1;
                break;

            case 'month':
            default:
                $weeks = 4;
        }

        #get the values for the past four weeks
        $days = $weeks * 7;
        for($i = 0; $i < $days; $i++)
        {
            $requestString = str_replace('{DATE}', $date->toString(), $requestStringTemplate);
            $request = new Piwik_API_Request($requestString);

            $iWeekday = $date->toString('N')-1;
            $uniqueVisitors[$iWeekday][$visitorKey] += $request->process();
            $date = $date->subDay(1);
        }

        $dataTable->addRowsFromSimpleArray($uniqueVisitors);

        return $dataTable;
    }

Hello,

we have the same problem. Our error message:

Open Flash Chart

JSON Parse Error [Syntax Error]
Error at character 0, line 1:

0: 

Thank you for your help.

Greetings

Heiko Bockelmann - viatoura AG

what if you try and replace the code in core/visualization/chart/verticalbar.php around line 65 by:

            if($this->displayPercentageInTooltip
                && $sum > 0)
            {
                $percentage = round(100 * $value / $sum);
                $displayPercentage = "($percentage%)";
            }

does the plotting work?

The best way to get started with plotting graph is to look at the plugin “ExampleUI” that shows how to use the graphs with simple examples.

[quote=matthieu @ May 25 2009, 12:03 AM) <{POST_SNAPBACK}>

what if you try and replace the code in core/visualization/chart/verticalbar.php around line 65 by:
            if($this->displayPercentageInTooltip
                && $sum > 0)
            {
                $percentage = round(100 * $value / $sum);
                $displayPercentage = "($percentage%)";
            }

does the plotting work?

At least the errors vanished style_emoticons/<#EMO_DIR#>/smile.gif I got only 0-values though. I came to the conclusion that the issue is my way of building the dataTable.

QUOTE (matthieu @ May 25 2009, 12:03 AM]The best way to get started with plotting graph is to look at the plugin "ExampleUI" that shows how to use the graphs with simple examples.[/quote]

This example was a very good hint (why did not i look there myself when other plugins gave didn’t help?) and gave me the right intentions. It works now for me.

For the sake of completeness:

    protected function getDataTable($name, $idSite, $period, $date )
    {
        Piwik::checkUserHasViewAccess( $idSite );
        $date = Piwik_Date::factory($date);

        $uniqueVisitorsPerWeekday = array(Piwik_Translate('Weekday_Weekday_Mon')    => 0,
                                          Piwik_Translate('Weekday_Weekday_Tue')    => 0,
                                          Piwik_Translate('Weekday_Weekday_Wed')    => 0,
                                          Piwik_Translate('Weekday_Weekday_Thu')    => 0,
                                          Piwik_Translate('Weekday_Weekday_Fri')    => 0,
                                          Piwik_Translate('Weekday_Weekday_Sat')    => 0,
                                          Piwik_Translate('Weekday_Weekday_Sun')    => 0,
                                    );

        //determine the method that should be used and create the api-string template
        switch ($name)
        {
            case 'UniqueVisitors':
                $method = 'VisitsSummary.getUniqueVisitors';
                break;

            case 'Visitors':
            default:
                $method = 'VisitsSummary.getVisits';
        }

        $requestStringTemplate = 'method=' . $method .'&idSite=' . $idSite . '&date={DATE}&period=day&format=original';

        switch ($period)
        {
            case 'year':
                $weeks = 52;
                break;
            
            case 'day':
            case 'week':
                $weeks = 1;
                break;

            case 'month':
            default:
                $weeks = 4;
        }

        #get the values for the past four weeks
        $days = $weeks * 7;
        for($i = 0; $i < $days; $i++)
        {
            $requestString = str_replace('{DATE}', $date->toString(), $requestStringTemplate);
            $request = new Piwik_API_Request($requestString);

            $sWeekday = Piwik_Translate('Weekday_Weekday_' .  $date->toString('D'));
            $uniqueVisitorsPerWeekday[$sWeekday] += $request->process();
            $date = $date->subDay(1);
        }

        #create DataTable object and return it
        $dataTable = new Piwik_DataTable();
        $dataTable->addRowsFromArrayWithIndexLabel($uniqueVisitorsPerWeekday);

        return $dataTable;
    }

I too faced the same error “Division By Zero”

Thanks for the solution.
Really it saved a lot of time.

I have a syntax erorr

Eyad: this is an old thread that you’ve hijacked. Care to elaborate on the error message that you’re seeing?

Oh thanks a a lot I also have the same issue hope so this post very helpful for me. I have some time syntax error. ButIncomplete sentence not every time. AnyInformal question suggestion? thanks

Hallo,
Sorry for digging up old posts but I have a problem with this plugin.
I have installed piwik 1.0 and I cannot make this plugin to work.
It gives me the following error:

init( $this->pluginName, __FUNCTION__, "Weekday.getWeekdayVisitsStatistics" ); $view->disableSearchBox(); return $this->renderView($view, $fetch); } }
Fatal error: Class 'Piwik_Weekday_Controller' not found in ******\core\FrontController.php on line 115
Call Stack
#    Time    Memory    Function    Location
1    0.0005    336456    {main}( )    ..\index.php:0
2    0.1516    7061888    Piwik_FrontController->dispatch( )    ..\index.php:60

Can anyone help me out?
Thanks for any help!
style_emoticons/<#EMO_DIR#>/smile.gif