Unable to view highcharts in my yii2 project - highcharts

I have installed the highcharts package in my project. Now I am trying to view a sample chart but I am getting an error.
use miloschuman\highcharts\Highcharts;
<?=
Highcharts::widget([
'options' => [
'title' => ['text' => 'Fruit Consumption'],
'xAxis' => [
'categories' => ['Apples', 'Bananas', 'Oranges']
],
'yAxis' => [
'title' => ['text' => 'Fruit eaten']
],
'series' => [
['name' => 'Jane', 'data' => [1, 0, 4]],
['name' => 'John', 'data' => [5, 7, 3]]
]
]
]);
?>
Error
Invalid Argument – yii\base\InvalidArgumentException
The file or directory to be published does not exist: F:\xampp\htdocs\mdc/vendor\bower/highcharts
Update 1
Below is my stack trace
Update 2
Below is my composer.json
{
"name": "yiisoft/yii2-app-advanced",
"description": "Yii 2 Advanced Project Template",
"keywords": ["yii2", "framework", "advanced", "project template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "dev",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "~2.0.13",
"yiisoft/yii2-bootstrap": "~2.0.0",
"yiisoft/yii2-swiftmailer": "~2.0.0",
"luoxiaojun1992/yii2-tinker": "*",
"kartik-v/yii2-grid": "#dev",
"kartik-v/yii2-widget-select2": "#dev",
"kartik-v/yii2-mpdf": "dev-master",
"moonlandsoft/yii2-phpexcel": "*",
"nirvana-msu/yii2-showloading": "1.0.*#dev",
"kartik-v/yii2-krajee-base": "^2.0",
"kartik-v/yii2-widget-spinner": "#dev",
"edwinhaq/yii2-simple-loading": "*",
"c006/yii2-submit-spinner": "*",
"kartik-v/yii2-detail-view": "*",
"fedemotta/yii2-cronjob": "*",
"kartik-v/yii2-widget-datetimepicker": "*",
"kartik-v/yii2-date-range": "dev-master",
"phpoffice/phpspreadsheet": "^1.2",
"linslin/yii2-curl": "*",
"kartik-v/yii2-widget-fileinput": "#dev",
"kartik-v/yii2-dialog": "*",
"google/apiclient": "^2.0",
"delight-im/str": "^2.4",
"mongosoft/yii2-soap-client": "dev-master",
"kartik-v/yii2-export": "#dev",
"ext-json": "*",
"miloschuman/yii2-highcharts-widget": "*",
"simialbi/yii2-widget-chart": "^1.0#dev",
"onmotion/yii2-widget-apexcharts": "dev-master",
"2amigos/yii2-chartjs-widget": "~2.0",
"kartik-v/yii2-bootstrap4-dropdown": "#dev",
"practically/yii2-chartjs": "dev-master",
"php-parallel-lint/php-console-color": "dev-master",
"nnnick/chartjs": "v2.9.3"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.0.0",
"yiisoft/yii2-gii": "~2.0.0",
"yiisoft/yii2-faker": "~2.0.0",
"codeception/base": "^2.2.3",
"codeception/verify": "~0.3.1"
},
"config": {
"process-timeout": 1800,
"fxp-asset": {
"enabled": false
}
},
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
},
"scripts": {
"post-install-cmd": "php init --env=Development --overwrite=n"
},
"autoload": {
"psr-4": {
"kartik\\spinner\\": "",
"nirvana\\showloading\\": ""
}
},
"repositories": [{
"type": "composer",
"url": "https://asset-packagist.org"
}]
}
Update 3
Removed highcharts package from composer.json and then executed composer update
F:\xampp\htdocs\mdc>composer require --prefer-dist miloschuman/yii2-highcharts-widget "*"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
- Installing bower-asset/highcharts (v7.2.1): Loading from cache
- Installing miloschuman/yii2-highcharts-widget (dev-master 260b946): Loading from cache
Package codeception/base is abandoned, you should avoid using it. No replacement was suggested.
Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead.
Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead.
Writing lock file
Generating autoload files
14 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Getting same error
Invalid Argument – yii\base\InvalidArgumentException
The file or directory to be published does not exist: F:\xampp\htdocs\mdc/vendor\bower/highcharts
Update 4
As per #Taron 1st solution I have backend/config/main.php
<?PHP
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
// require(__DIR__ .'/main-local.php')
);
return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module'
],
'api' => [
'class' => 'backend\modules\api\Api',
],
],
'timeZone' => 'Asia/Karachi',
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
'parsers' => [
'application/json' => 'yii\web\JsonParser',
],
'enableCookieValidation' => false,
'enableCsrfValidation' => false,
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
],
'session' => [
// this is the name of the session cookie used for login on the backend
'name' => 'advanced-backend',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
],
'params' => $params,
];
How can I get rid of this error?
Any help would be highly appreciated

Looks like bower assets stored in path /vendor/bower-assets, but your script tries to load assets from vendor/bower (bower assets path error). Try solution bellow, I hope one of them will help you.
Solution first:
Just add aliases bellow to your config file/files (config/web.php)
'aliases' => [
'#bower' => '#vendor/bower-asset',
'#npm' => '#vendor/npm-asset',
],
Solution second:
Remove composer.lock file
Add package fxp: composer globalrequire "fxp/composer-asset-plugin:~1.1.1"
Reinstall composer: composer --prefer-dist install

Related

Scatter Highcharts responsive issue Yii2

I am using scatter chart in Yii2 using the following extension
https://github.com/miloschuman/yii2-highcharts
For responsive I have passed parameters like this.
<?php
use miloschuman\highcharts\Highcharts;
echo Highcharts::widget([
'options' => [
'responsive' => [
'rules'=> [
[
'condition'=>
[
'maxWidth' => 500,
],
'chartOptions'=> [
'legend' => [
'enabled'=> true,
'align'=> 'center',
'verticalAlign'=> 'bottom',
'layout'=> 'horizontal',
],
],
]
],
],
]);
?>
But its not working for mobile as well as tablet.Can any one have idea?
Thanks!

Any element in categories Highcharts widget be a link

I have bar chart with Highcharts widget in yii2 project. I want to create hyperlink the category names so that clicking on the label (not the bar) loads the URL in a new window. How can do it?
In Highcharts used label in option but when I use that I get syntax error.
<?php
$x = array("a", "b", "c");
$y = array_values(array(4, 2, 6));
echo Highcharts::widget([
'options' => [
'chart' => [
'type' => 'column',
'zoomType' => 'x',
],
'title' => [
'text' => 'Project chart',
],
'xAxis' => [
'categories' => $x,
],
'yAxis' => [
'title' => [
'text' => 'Count',
],
],
'series' => [
[
'type' => 'column',
'name' => 'p1',
'data' => $y,
],
],
]
]);
?>
I want to each element in $x be a link.
Please tell me what I should do in the code that I posted because they are javascript code and I can't properly use my own code.

Parsing Quoted Strings and DateTime Offset - GROK and Logstash

With Grok Debuger I am trying to parse some custom data:
1 1 "Device 1" 1 "Input 1" 0 "On" "Off" "2020-01-01T00:00:00.1124303+00:00"
So far I have:
%{INT:id} %{INT:device} %{QUOTEDSTRING:device_name} %{INT:input}
%{QUOTEDSTRING:input_name} %{INT:state} %{QUOTEDSTRING:on_phrase}
%{QUOTEDSTRING:off_phrase} \"%{TIMESTAMP_ISO8601:when}\"
However, I am getting things like double quotes around strings %{QUOTEDSTRING), and two lots of hours and minutes with the time and date %{TIMESTAMP_ISO8601:when}
{
"id": [
[
"1"
]
],
"device": [
[
"1"
]
],
"device_name": [
[
""Device 1""
]
],
"input": [
[
"1"
]
],
"input_name": [
[
""Input 1""
]
],
"state": [
[
"0"
]
],
"on_phrase": [
[
""On""
]
],
"off_phrase": [
[
""Off""
]
],
"when": [
[
"2020-01-01T00:00:00.1124303+00:00"
]
],
"YEAR": [
[
"2020"
]
],
"MONTHNUM": [
[
"01"
]
],
"MONTHDAY": [
[
"01"
]
],
"HOUR": [
[
"00",
"00"
]
],
"MINUTE": [
[
"00",
"00"
]
],
"SECOND": [
[
"00.1124303"
]
],
"ISO8601_TIMEZONE": [
[
"+00:00"
]
]
}
Also, I am a little stuck when it comes to the logstash.conf as I am not sure what I would put as the index in the output. The following code is from a previous example from github:
input {
beats {
port => 5044
}
}
filter {
grok {
match => { "message" => "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}" }
}
}
output {
elasticsearch {
hosts => "elasticsearch:9200"
manage_template => false
index => "sample-%{+YYYY.MM.dd}"
}
}
I'm guessing mine would look something like this:
input {
beats {
port => 5044
}
}
filter {
grok {
match => { "message" => "%{INT:id} %{INT:device} %{QUOTEDSTRING:device_name} %{INT:input} %{QUOTEDSTRING:input_name} %{INT:state} %{QUOTEDSTRING:on_phrase} %{QUOTEDSTRING:off_phrase} \"%{TIMESTAMP_ISO8601:when}\"" }
}
}
output {
elasticsearch {
hosts => "elasticsearch:9200"
manage_template => false
index => "sample-%{????????}"
}
}
Again I'm unclear as to what I am supposed to do with "sample-%{????????}"
In regard to the double-double-quotes: just use DATA instead of QUOTEDSTRING:
"%{DATA:device_name}"
Duplicated entries in the hours and minutes come from the timezone: first entry is the actual hour, the second one is the hour of the timezone. Same for the minutes.
To get rid of it you would need a custom pattern:
"(?<when>%{YEAR}-%{MONTHNUM}-%{MONTHDAY}[T ]%{HOUR}:?%{MINUTE}(?::?%{SECOND})?(?<ISO8601_TIMEZONE>Z|[+-](?:2[0123]|[01]?[0-9])(?::?(?:[0-5][0-9])))?)"
(if you are not interested in parsing the timestamp at all, just use DATA again).
So, your pattern might look like this:
%{INT:id} %{INT:device} "%{DATA:device_name}" %{INT:input} "%{DATA:input_name}" %{INT:state} "%{DATA:on_phrase}" "%{DATA:off_phrase}" "(?<when>%{YEAR}-%{MONTHNUM}-%{MONTHDAY}[T ]%{HOUR}:?%{MINUTE}(?::?%{SECOND})?(?<ISO8601_TIMEZONE>Z|[+-](?:2[0123]|[01]?[0-9])(?::?(?:[0-5][0-9])))?)"
Regarding index:
you can omit it completely then the default one is used: logstash-%{+YYYY.MM.dd}
you can use sample-%{+YYYY.MM.dd} if you want to have separate indexes for each day
you can use sample- to have just one index
you can use any other combination of the fields in your index pattern

Swagger UI - Try it Out! Returns whole Swagger Doc

When I ran following command :
rake swagger:docs
It returns me proper JSON files for each controllers.
When I access swagger-ui, it gives me proper page :
But when I click on Try it Out!, it returns me whole JSON like below :
I am new to Swagger. Can someone please help me out, where am I going wrong ?
UPDATE :
My public directory structure :
UPDATE
trucks.json :
{
"apiVersion": "v1",
"swaggerVersion": "1.2",
"basePath": "http://localhost:3000",
"resourcePath": "trucks",
"apis": [
{
"path": "/api/v1/trucks.json",
"operations": [
{
"summary": "Fetches all Trucks",
"parameters": [
{
"paramType": "header",
"name": "X-Auth-Token",
"type": "string",
"description": "Authentication Token",
"required": true
}
],
"responseMessages": [
{
"code": 401,
"responseModel": null,
"message": "Unauthorized"
},
{
"code": 406,
"responseModel": null,
"message": "The request you made is not acceptable"
}
],
"nickname": "API::V1::Trucks#index",
"method": "get"
}
]
}
],
"authorizations": null
}
Figured out the solution. Posting so that if anyone stumbles upon can try it out.
My swagger docs configuration looked like below :
Swagger::Docs::Config.register_apis({
'v1' =>{
:api_extension_type => :json,
:api_file_path => "public",
:base_path => 'http://localhost:3000',
:parent_controller => ApplicationController,
:base_api_controller => ActionController::Base,
:camelize_model_properties => false,
:clean_directory => true,
:attributes => {
:info => {
"title" => "Swagger Yattya",
"description" => "Yattya api documentation",
"termsOfServiceUrl" => "http://helloreverb.com/terms/",
"contact" => "apiteam#wordnik.com",
"license" => "Apache 2.0",
"licenseUrl" => "http://www.apache.org/licenses/LICENSE-2.0.html"
}
}
}
})
The first line wasn't required :
:api_extension_type => :json
Removed this line from configuration and worked like a charm!

Why is all incoming sms/phone call data repeated in Twilio request?

I'm seeing all the pertinent data for an incoming phone call and sms repeated when I receive requests from Twilio to handle the communication:
{
AccountSid: [ 'xxx', 'xxx' ],
ToZip: [ '30680', '30680' ],
FromState: [ 'NY', 'NY' ],
Called: [ '+111', '+111' ],
FromCountry: [ 'US', 'US' ],
CallerCountry: [ 'US', 'US' ],
CalledZip: [ '30680', '30680' ],
Direction: [ 'inbound', 'inbound' ],
FromCity: [ 'NEW YORK', 'NEW YORK' ],
CalledCountry: [ 'US', 'US' ],
CallerState: [ 'NY', 'NY' ],
CallSid: [ 'xxx', 'xxx' ],
CalledState: [ 'GA', 'GA' ],
From: [ '+222', '+222' ],
CallerZip: [ '10028', '10028' ],
FromZip: [ '10028', '10028' ],
ApplicationSid: [ 'xxx', 'xxx' ],
CallStatus: [ 'ringing', 'ringing' ],
ToCity: [ 'STATHAM', 'STATHAM' ],
ToState: [ 'GA', 'GA' ],
To: [ '+111', '+111' ],
ToCountry: [ 'US', 'US' ],
CallerCity: [ 'NEW YORK', 'NEW YORK' ],
ApiVersion: [ '2010-04-01', '2010-04-01' ],
Caller: [ '+222', '+222' ],
CalledCity: [ 'STATHAM', 'STATHAM' ]
}
This was happening because my webserver redirects all http traffic to https. The redirect causes twilio to repeat the information (like the to and from number). I hope this saves someone the trouble of figuring this out in the future.

Resources