Recreate Visitsummary with custom data

Hello everybody,

I want to create a plugin which look like Visitsummary->Overview page. (Click on sparkline load the evolutionGraph).

I load my data from an other server(php/cURL).

The problem is that the sparklines are correctly displayed BUT are NOT clickable so nothing happens the evolutionGraph is not updated.

API.php


public function get( $idSite, $period, $date, $segment = false, $columns = false)
	{	

		$url     = 'http://www.urltoserver.com/data.php';

        
        
        
        if(strpos($date,',') === FALSE)
            $p = Piwik_Period::factory($period,Piwik_Date::factory($date));
        else
            $p = new Piwik_Period_Range('range',$date);
       
        
        $fields = array(data.....);
        
       //cURL method which grep data from url
        $dataRow = $this->fetchData($url,$fields);
		
		
		// convert this array to a DataTable object
		$dataTable = new Piwik_DataTable();
		$dataTable->addRowsFromArrayWithIndexLabel($dataRow);
		return $dataTable;
	}.

Controller.php


public function index()
	{
		$view = Piwik_View::factory('index');
		$this->setPeriodVariablesView($view);
        $columns = Piwik_Common::getRequestVar('columns');
		$view->graphEvolutionVisitsSummary = $this->getEvolutionGraph( true, array($columns) );
		$this->setSparklinesAndNumbers($view);
		echo $view->render();
	}
	
	public function getSparklines()
	{
		$view = Piwik_View::factory('sparklines');
		$this->setPeriodVariablesView($view);
		$this->setSparklinesAndNumbers($view);
		echo $view->render();
	}

	public function getEvolutionGraph( $fetch = false, $columns = false)
	{
		$view = $this->getLastUnitGraph($this->pluginName, __FUNCTION__, "TPlug.get");
		if(empty($columns))
		{
			$columns = Piwik_Common::getRequestVar('columns');
		}
		$columns = !is_array($columns) ? array($columns) : $columns;
		//$view->graphEvolutionVisitsSummary =  $this->getEvolutionGraph( true, array($columns) );
		$view->setColumnsToDisplay($columns);
		
		
		return $this->renderView($view, $fetch);
	}
    
 

	
	protected function setSparklinesAndNumbers($view)
	{
		$view->urlSparklineNbVisits 		= $this->getUrlSparkline( 'getEvolutionGraph', array('columns' => array('Cols')));
		$view->urlSparklineNbActions 		= $this->getUrlSparkline( 'getEvolutionGraph', array('columns' => array('SCols')));

//Assign template variables
}		
		

TPlug.php


// ...
function getListHooksRegistered()
	{
		$hooks = array(
			'Menu.add' => 'addMenus',
		);
		return $hooks;
	}
   
	


	function addMenus()
	{
		$menus = array(
            //'Overview' => 'PlugDataTable',
            'Graph' => 'index',
						
           	
		);

		Piwik_AddMenu('Chat', '', array('module' => 'TPlug', 'action' => 'PlugDataTable'), true, 29);
		$order = 1;
		foreach($menus as $subMenu => $action) 
		{
			Piwik_AddMenu('Chat', $subMenu, array('module' => 'TPlug', 'action' => $action, 'columns' => 'Chats'), true, $order++);
		}
	}

I hope that somebody can help me
Greetz
Acers

Its funny even when I do an exact copy of the VisitsSummary plugin and rename only the classes and change the third parameter in Piwik_AddMenu (module => MyPlugin) it doesnt update the evolutionGraph :open_mouth:

Ok I found the problem by myself. When you want rebuild a page like VisitsSummary you have to change the first line of index.tpl (graphId).

Note : It would be better that piwik would that dynamically …

Thanks for putting the solution. Definitely there are many things that could be improved in Piwik, if you have ideas after building a plugin please let us know in a forum post your feedback (or patches)

Happy New Year! If you are still using Piwik and interested in the awesome new feature of “Creating a Custom Segment in Piwik and apply to reports in Real time!” we need YOUR help, with a little or big donation at: http://crowdfunding.piwik.org/custom-segments-editor/

This will allow to dynamically add or edit, a new set of rules for example “Show all visitors from USA and using Firefox and using Google”. This will be done via a simple to use interface. See screenshots and more info here: http://crowdfunding.piwik.org/custom-segments-editor/

We are crowd funding the future of Piwik and this feature in particular. With your help we can do it.

Thanks

Matthieu