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
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;
}
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