Pie Chart showing "other" when it should show data - google-visualization

I have implemented Google Pie Chart.
All works perfectly but when i try to add data less than 10 it do not plot on chart instead of that it add a new entry under legend named - "Other"
My Script is
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Age Difference'],
['>10', 15],
['10-15', <?php echo $agecnt2;?>],
['16-20', <?php echo $agecnt3;?>],
['21-25', <?php echo $agecnt4;?>],
['26-30', <?php echo $agecnt5;?>],
['31-35', <?php echo $agecnt6;?>],
['36-40', <?php echo $agecnt7;?>],
['41-45', <?php echo $agecnt8;?>],
['46-50', <?php echo $agecnt9;?>],
['51-55', <?php echo $agecnt10;?>],
['56-60', <?php echo $agecnt11;?>],
['61-65', <?php echo $agecnt12;?>],
['66-70', <?php echo $agecnt13;?>],
['71-75', <?php echo $agecnt14;?>],
['76-80', <?php echo $agecnt15;?>],
['>80', <?php echo $agecnt16;?>]
]);
var options = {
title: 'Age Difference'
};
var chart = new google.visualization.PieChart(document.getElementById('chart_div4'));
chart.draw(data, options);
}
</script>

The Google Pie chart groups all "small" slices into an "Other" group. As a default, any group that would have a default smaller than 1/2degree is grouped into the "Other" section. You can modify the sliceVisibilityThreshold (described here) to minimize/eliminate this effect.

I had a similar issue - just that the numbers were actually not too much different.
The datatable rendered perfectly as ColumnChart, but failed to show slices as PieChart.
What resolved the issue for me was casting the values in php to integer with intval().
Apparently the ColumnChart visualization is forgiving, while the PieChart is not when it comes to values other than integers.

For me the problem was that my php code was still a string because of echo.
So i did this:
parseInt("<?php echo $phpvalue; ?>")
and it worked.

Related

opencart 2.3 same image for sub categories

I am using opencart 2.3 and in category page, all sub categories have same image. Title is different, in backend and database images are different.
Removed everything from /image/cache with no effect.
Tried to add $image into $data['categories'] array, in controller/product/category.php but is the same.
This is my code from <theme>/product/category.tpl
<?php if ($categories) { ?>
<?php foreach ($categories as $category) { ?>
<img src="<?php echo $thumb; ?>" alt="<?php echo $category['name']; ?>" /><p><?php echo $category['name']; ?></p>
<?php } ?>
<?php } ?>
Can't find nothing else to fix this. Will be very appreciate, if you can help.
Fixed by adding this:
'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get($this->config->get('config_theme') . '_image_category_width'), $this->config->get($this->config->get('config_theme') . '_image_category_height'))
to $data['categories'] array.
:)

Hide subcategories from showing in sidebar module

Opencart 2.3.02
How can I hide the subcategories from showing in the sidebar module? I have it on the left hand column. It shows up in the main top menu under main categories and thats fine but i want it hidden in the side menu.
Thanks
Category is one of default Opencart modules, you can edit its tpl file to achieve what you want, so open this file:
catalog/view/theme/default/template/extension/module/category.tpl
remove this section:
<?php if ($category['children']) { ?>
<?php foreach ($category['children'] as $child) { ?>
<?php if ($child['category_id'] == $child_id) { ?>
- <?php echo $child['name']; ?>
<?php } else { ?>
- <?php echo $child['name']; ?>
<?php } ?>
<?php } ?>
<?php } ?>
If you are using different theme and still see subcategories, try to edit this file:
catalog/view/theme/YOUR-THEME/template/extension/module/category.tpl

opencart how to add manufacturers list like categories list

I just start with Opencart. I need to have list of brands, like llist of catgories. I try so:
<div class="box">
<div class="box-heading"><?php echo "По брендам" ?></div>
<div class="box-content">
<ul class="box-category">
<?php foreach ($manufacturers as $manufacturer) { ?>
<li>
<?php if ($manufacturer['manufacturer_id'] == $manufacturer_id) { ?>
<?php echo $manufacturer['name']; ?>
<?php } else { ?>
<?php echo $manufacturer['name']; ?>
<?php } ?>
<?php if ($manufacturer['children']) { ?>
<ul>
<?php foreach ($manufacturer['children'] as $child) { ?>
<li>
<?php if ($child['manufacturer_id'] == $child_id) { ?>
- <?php echo $child['name']; ?>
<?php } else { ?>
- <?php echo $child['name']; ?>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
I add this code in default/template/module/category.tpl file.
I get this error: Notice: Undefined variable: manufacturers in....
How should I do this???
Thanks.
category.tpl is the template for the category controller. Its purpose is to show categories. Try to direct your browser to the http://your.site/index.php?route=product/manufacturer and you will get list of manufacturers. The template is /catalog/view/theme/default/template/product/manufacturer_list.tpl.
Your error is a result of one simple thing: the $manufacturers variable is not defined in ControllerModuleCategory controller (aka category.php). If you want use a variable in a template, you must define it in a relevant controller.
In order to obtain list of manufacturers exactly in the /catalog/view/theme/default/template/module/category.tpl (even if it isn't the purpose of this module), you need be done with few things:
1) In the /catalog/model/catalog/manufacturer.php file (model ModelCatalogManufacturer) add function (this function will help you to obtain the list of manufacturers from the database):
public function getManufacturerByCategory($category_id) {
$query = $this->db->query("SELECT m.*
FROM " . DB_PREFIX . "product p
RIGHT JOIN " . DB_PREFIX . "product_to_category p2c ON
p.product_id = p2c.product_id
LEFT JOIN " . DB_PREFIX . "manufacturer m ON
p.manufacturer_id = m.manufacturer_id
WHERE
p2c.category_id = " . (int)$category_id . " AND
m.manufacturer_id IS NOT NULL
GROUP BY m.manufacturer_id");
return $query->rows;
}
2) In the /catalog/controller/module/category.php file (aka ControllerModuleCategory controller), prior to if (file_exists(DIR_TEMPLATE . $this->config->get('confi... insert the code:
if (isset($this->request->get['path'])) {
$category_id = array_pop($parts);
$this->load->model('catalog/manufacturer');
$this->data['manufacturers'] = $this->model_catalog_manufacturer->getManufacturerByCategory($category_id);
} else {
$this->data['manufacturers'] = array();
}
(Keep in mind $this->data['manufacturers'] from the controller will be available in the template as $manufacturers. $this->data['categories'] will be $categories, $this->data['another_var'] will be $another_var and so on.)
And since the moment you can use your foreach ($manufacturers as $manufacturer) in the category module template (the place where you did try the foreach, when you've received "Undefined variable" error) in order to output list of manufacturers which are applied to products from current category.
Best way is create another module, "manufacturer" module, instead of illegitimate using of category module. But I'm not sure that right now you are ready for this challenge.
BTW, I'm all for shadyyx's link to the Jay Gilford's guide. It is awesome quick start guide for beginners.
I have light solution:
Just add code in Controller:category.php:
$this->load->model('catalog/manufacturer');
$this->data['mans'] = $this->data['manufacturers'] =
$this->model_catalog_manufacturer->getManufacturers();
And View: category.tpl:
<?php
foreach($mans as $mans_value)
{
var_dump($mans_value);
}
?>

Joomla! Virtuemart2 Change product details link to open in new browser window

is there any way to open the product details from category view in a new browser window? The current code for the button is:
<p>
<?php // Product Details Button
echo JHTML::link ($product->link, JText::_ ('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name, 'class' => 'product-details'));
?>
</p>
I am using Joomla! 2.5.11 and VM 2.0.22a
In addition to title and class, you can pass third parameter to the array:
array('title' => $product->product_name, 'class' => 'product-details', 'target' => '_blank')
I have changed the following code overriding com_virtuemart/views/category/default.php:
<?php // Product Details Button
echo JHTML::link ($product->link, JText::_ ('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name, 'class' => 'product-details')); ?>
To:
<?php $url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $product->virtuemart_category_id . '&tmpl=component'); ?>
...and for the text link:
<a class="product-details" href="<?php echo $product->link ?>" target="_blank"><?php echo JText::_('COM_VIRTUEMART_PRODUCT_DETAILS') ?></a>

Joomla Development Publish / unpublish not working

I have a simple component following the hello world tutorial for the most part, and everything works except i've added a publish / unpublish icons to the toolbar and to the list itself (the small green / red circles).
The toolbar icons work and they can change the state no problem, but the small icons do not, here is the code I have:
view.html.php:
protected function addToolBar()
{
JToolBarHelper::title(JText::_('COM_MADS_MANAGER_OBJECTS'));
JToolBarHelper::publishList($task = 'objects.publish', $alt = 'Publish');
JToolBarHelper::unpublishList($task = 'objects.unpublish', $alt = 'Unpublish');
JToolBarHelper::deleteListX('', 'objects.delete');
JToolBarHelper::editListX('object.edit');
JToolBarHelper::addNewX('object.add');
}
tmpl > body:
<?php
// No direct access to this file
defined('_JEXEC') or die;
?>
<?php foreach($this->items as $i => $item): ?>
<tr class="row<?php echo $i % 2; ?>">
<td><?php echo $item->id; ?></td>
<td><?php echo JHtml::_('grid.id', $i, $item->id); ?></td>
<td><?php echo $item->title; ?></td>
<td><?php echo $item->description; ?></td>
<td align="center"><?php $published = JHTML::_('grid.published', $item, $i); echo $published;?></td>
</tr>
<?php endforeach; ?>
I am using the built in publish / unpublish function and did not create one of my own.
Tables:
<?php
// No direct access to this file
defined('_JEXEC') or die;
jimport('joomla.database.table');
class MAdsTableObjects extends JTable
{
var $id = null;
var $title = null;
var $description = null;
var $published = 0;
function __construct(&$db)
{
parent::__construct('#__mads_objects', 'id', $db);
}
}
?>
I figured it out after A LOT OF FREKIN HEADACHE and wasted time, it should be:
<?php echo JHtml::_('jgrid.published', $item->published, $i, 'objects.',true); ?>
where objects. is the name of my view / controller / model for the listing.
I think you should have a state field in the db, to store the status
state tinyint(3)
Than try using:
echo JHtml::_('grid.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder);