[XTR] Chart Statistics

[XTR] Chart Statistics 1.0.0

No permission to download
Love this, also we do not run the resource manager so that would be neat to have the option to exclude that.

Edit: I'm unable to get this to show up, does it require the resource manager to even display? I've added group permissions. Added the widget. Made sure the add-on was enabled and that enable chart statistics is checked. Still nothing.

Edit 2: I see the errors in the admin cp looking for resource manager. I guess it is required. No worries, will patiently wait for a version that works without the RM.

What is the error, with the stack trace and request state?
 
Here ya go:

Code:
XF\Db\Exception: Error rendering widget: MySQL statement prepare error [1146]: Table 'landcruiser.xf_rm_resource' doesn't exist src/XF/Db/AbstractStatement.php:230
Generated by: El Chorizo Mar 7, 2024 at 2:48 AM

Code:
SELECT COUNT(resource_id)
		FROM xf_rm_resource
		
------------

#0 src/XF/Db/Mysqli/Statement.php(198): XF\Db\AbstractStatement->getException('MySQL statement...', 1146, '42S02')
#1 src/XF/Db/Mysqli/Statement.php(40): XF\Db\Mysqli\Statement->getException('MySQL statement...', 1146, '42S02')
#2 src/XF/Db/Mysqli/Statement.php(56): XF\Db\Mysqli\Statement->prepare()
#3 src/XF/Db/AbstractAdapter.php(96): XF\Db\Mysqli\Statement->execute()
#4 src/XF/Db/AbstractAdapter.php(152): XF\Db\AbstractAdapter->query('
		SELECT COUNT...', Array)
#5 src/addons/XENTR/ChartStatistics/Widget/ChartStatistics.php(22): XF\Db\AbstractAdapter->fetchOne('
		SELECT COUNT...')
#6 internal_data/code_cache/widgets/_21_chartstats.php(5): XENTR\ChartStatistics\Widget\ChartStatistics->render()
#7 src/XF/Template/Templater.php(7729): XF\SubContainer\Widget->{closure}(Object(XenSoluce\CustomColorsPicker\XF\Template\Templater), Array, Array)
#8 src/XF/SubContainer/Widget.php(168): XF\Template\Templater->renderWidgetClosure(Object(Closure), Array)
#9 src/XF/Template/Templater.php(1940): XF\SubContainer\Widget->getCompiledWidget(Array, Array)
#10 internal_data/code_cache/templates/l1/s3/public/forum_list.php(216): XF\Template\Templater->widgetPosition('forum_list_side...', Array)
#11 src/XF/Template/Templater.php(1655): XF\Template\Templater->{closure}(Object(XenSoluce\CustomColorsPicker\XF\Template\Templater), Array, NULL)
#12 src/addons/MaZ/AUN/XF/Template/Templater.php(39): XF\Template\Templater->renderTemplate('forum_list', Array, true, NULL)
#13 src/XF/Template/Template.php(24): MaZ\AUN\XF\Template\Templater->renderTemplate('public:forum_li...', Array)
#14 src/XF/Mvc/Renderer/Html.php(50): XF\Template\Template->render()
#15 src/XF/Mvc/Dispatcher.php(460): XF\Mvc\Renderer\Html->renderView('XF:Forum\\Listin...', 'public:forum_li...', Array)
#16 src/XF/Mvc/Dispatcher.php(442): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#17 src/XF/Mvc/Dispatcher.php(402): XF\Mvc\Dispatcher->renderReply(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#18 src/XF/Mvc/Dispatcher.php(60): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#19 src/XF/App.php(2487): XF\Mvc\Dispatcher->run()
#20 src/XF.php(524): XF\App->run()
#21 index.php(20): XF::runApp('XF\\Pub\\App')
#22 {main}

Code:
array(4) {
  ["url"] => string(8) "/forums/"
  ["referrer"] => string(43) "https://www.landcruiserforum.com/whats-new/"
  ["_GET"] => array(1) {
    ["/forums/"] => string(0) ""
  }
  ["_POST"] => array(0) {
  }
}

Just looks like it's missing the necessary tables that come with the resource manager add-on, which we don't have installed.
 
I have installed this widget in my forum but it doesn't work on any style. Not even the default one.

Ozzy47 Can you help us about this? I saw that it works on your site

 
I have installed this widget in my forum but it doesn't work on any style. Not even the default one.

Ozzy47 Can you help us about this? I saw that it works on your site


Did you give the usergroups permission to view it? And do you have the XF Resources Manager installed? Any errors in your Admin CP like the ones I posted above?

The mod does require the resource manager for now.
 
There's quite a lot of bugs in this but you can replace the ChartStatistics.php file with:

Code:
<?php

/*
 * Created on 08.11.2020
 * HomePage: https://xentr.net
 * Copyright (c) 2019 XENTR | XenForo Add-ons - Styles -  All Rights Reserved
 */

namespace XENTR\ChartStatistics\Widget;

use \XF\Widget\AbstractWidget;

class ChartStatistics extends AbstractWidget
{
    public function render()
    {
           
        // Prepare ViewParams
       
        $viewParams = [
            'forumStatistics' => $this->app->forumStatistics
        ];
       
        // Send to Widget
        return $this->renderer('xtr_chart_statistics', $viewParams);
    }

    public function getOptionsTemplate()
    {
       return null;
    }
}

Replace the xtr_chart_statistics template with

Code:
<xf:if is="{$xf.options.chartStatistics_Enable}">
    <xf:if is="{{ $xf.visitor.hasPermission('ChartStatistics', 'view') }}">
        <div class="block"{{ widget_data($widget) }}>
            <div class="block-container">
                <h3 class="block-minorHeader">{$title}</h3>              
                <canvas id="xentrChart" width="{$xf.options.chartBlock_width}" height="{$xf.options.chartBlock_height}"></canvas>              
                <xf:css>
                    #xentrChart {
                        margin-top: {{ property('paddingMedium') }};
                    }
                </xf:css>
                <xf:js>
                    var ctx = document.getElementById("xentrChart").getContext('2d');
                    ctx.height = {$xf.options.chartBlock_height};
                    ctx.width = {$xf.options.chartBlock_width};
                    var xtrChart = new Chart(ctx, {
                        type: '{$xf.options.ChartType}',
                        data: {
                            labels: ["{{ phrase('threads') }}", "{{ phrase('messages') }}", "{{ phrase('members') }}"],
                            datasets: [{
                            label: '{$xf.options.chartLabel}',
                            data: [{$forumStatistics.threads}, {$forumStatistics.messages}, {$forumStatistics.users}],
                            backgroundColor: [
                                    '{{ property('ChartStatistics_threads') }}',
                                    '{{ property('ChartStatistics_messages') }}',
                                    '{{ property('ChartStatistics_users') }}'
                                ],
                             borderColor: [
                                    '{{ property('ChartStatistics_threads_border') }}',
                                    '{{ property('ChartStatistics_messages_border') }}',
                                    '{{ property('ChartStatistics_users_border') }}'
                                ],
                              borderWidth: 1
                            }]
                        },
                        options: {
                            tooltips: {
                              callbacks: {
                                    label: function(tooltipItem, data) {
                                        var value = data.datasets[0].data[tooltipItem.index];
                                        value = value.toString();
                                        value = value.split(/(?=(?:...)*$)/);
                                        value = value.join(',');
                                        return value;
                                    }
                              }
                            },
                            legend: {
                                display: {$xf.options.chartLegand_Enable}
                             },
                            scales: {
                                 yAxes: [{
                                    stacked: false
                                }],
                                yAxes: [{
                                    ticks: {
                                        beginAtZero: true
                                    }
                                }]
                            }
                        }                  
                    });
                </xf:js>
           
                <xf:if is="{$xf.options.chartBlock_Statistics}">
                    <div class="block-body block-row">          
                        <dl class="pairs pairs--justified">
                            <dt><i class="fad fa-list-alt" aria-hidden="true"
                                   style="color:<xf:if is="{$xf.options.chartBlock_Statistics_Color}">{{ property('ChartStatistics_threads_border') }}</xf:if>"></i> {{ phrase('threads') }}</dt>
                            <dd>{$forumStatistics.threads|number}</dd>
                        </dl>
                        <dl class="pairs pairs--justified">
                            <dt><i class="fad fa-comments" aria-hidden="true"
                                   style="color:<xf:if is="{$xf.options.chartBlock_Statistics_Color}">{{ property('ChartStatistics_messages_border') }}</xf:if>"></i> {{ phrase('messages') }}</dt>
                            <dd>{$forumStatistics.messages|number}</dd>
                        </dl>                      
                        <dl class="pairs pairs--justified">
                            <dt><i class="fad fa-users" aria-hidden="true"
                                   style="color:<xf:if is="{$xf.options.chartBlock_Statistics_Color}">{{ property('ChartStatistics_users_border') }}</xf:if>"></i> {{ phrase('members') }}</dt>
                            <dd>{$forumStatistics.users|number}</dd>
                        </dl>
                        <dl class="pairs pairs--justified">
                            <dt><i class="fad fa-user-plus" aria-hidden="true"></i> {{ phrase('latest_member') }}</dt>
                            <dd><xf:username user="{$forumStatistics.latestUser}" /></dd>
                        </dl>
                    </div>
                </xf:if>
            </div>
        </div>
    </xf:if>
</xf:if>

The chart legend doesn't show correctly on all charts so you may wish to hide that in the options but if you replace the file and template contents it should work if you don't have the resource manager installed. There is probably a better solution but it "works"

Edit: Looks like they have updated the addon on their website to address the resources problem.
 

Attachments

  • chart1.webp
    chart1.webp
    7 KB · Views: 1
  • chart2.webp
    chart2.webp
    9.4 KB · Views: 1
Last edited:
Back
Top Bottom