I'm trying to utilise the Yii2 Flot extension with more or less success. However, I'm having trouble altering the labels of a pie-chart using a labelFormatter function.
This is the extension I'm using: bburim/flot
Here is the code I have so far, it generates a nice chart, but I cannot alter the labels.
Any help is appreciated.
echo Chart::widget(
[
'data' => [
['label' => 'Series1', 'data' => [1, 12]],
['label' => 'Series2', 'data' => [1, 16]],
['label' => 'Series3', 'data' => [1, 89]],
['label' => 'Series4', 'data' => [1, 44]],
['label' => 'Series5', 'data' => [1, 38]],
],
'options' => [
'series' => [
'pie' => [
'show' => true,
'label' => [
'show' => true,
'treshold' => 0.1,
'radius' => 0.6,
'value' => 'value',
],
],
],
'grid' => [
'hoverable' => true,
],
'legend' => [
'position' => 'nw',
'show' => true,
'font' => [
'size' => 16,
],
'margin' => 10,
'backgroundOpacity' => 0.5,
],
],
'plugins' => [
Plugin::PIE,
],
'htmlOptions' => [
'class' => 'chartdiv',
],
]
);
That is a pretty broad term to say customize, I will assume it means providing custom label text, its pretty simple and straight forward you just need to use the new JsExpression() for the callback function to work correctly
echo Chart::widget(
[
'data' => [
['label' => 'Series1', 'data' => [1, 12]],
['label' => 'Series2', 'data' => [1, 16]],
['label' => 'Series3', 'data' => [1, 89]],
['label' => 'Series4', 'data' => [1, 44]],
['label' => 'Series5', 'data' => [1, 38]],
],
'options' => [
'series' => [
'pie' => [
'show' => true,
'label' => [
'show' => true,
'treshold' => 0.1,
'radius' => 0.6,
'value' => 'value',
],
],
],
'grid' => [
'hoverable' => true,
],
'legend' => [
'labelFormatter' => new JsExpression("function(label, series) {
// series is the series object for the label
return 'Custom Label for '+series.label+'';
}"),
'position' => 'nw',
'show' => true,
'font' => [
'size' => 16,
],
'margin' => 10,
'backgroundOpacity' => 0.5,
],
],
'plugins' => [
Plugin::PIE,
],
'htmlOptions' => [
'class' => 'chartdiv',
],
]
);
On a side note I wont use that repo as the owner seems to be unresponsive since 2015 not a single reply on the issues, you might have to maintain or fix the bugs your self so better fork the repo and use your own customized version
Related
I'm getting this error and not sure why. Here's my code :
$genesis_sample_shared_content = genesis_get_config( 'onboarding-shared' );
return [
'starter_packs' => [
'black-white' => [
'title' => __( 'Black & White', 'genesis-sample' ),
'description' => __( 'A pack with a homepage designed with black and white images.', 'genesis-sample' ),
'thumbnail' => get_stylesheet_directory_uri() . '/config/import/images/thumbnails/home-black-white.jpg',
'demo_url' => 'https://demo.studiopress.com/genesis-sample/',
'config' => [
'dependencies' => [
'plugins' => $genesis_sample_shared_content['plugins'],
],
'content' => array_merge(
[
'homepage' => [
'post_title' => 'Homepage',
'post_content' => require dirname( __FILE__ ) . '/import/content/home-black-white.php',
'post_type' => 'page',
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed',
'meta_input' => [
'_genesis_layout' => 'full-width-content',
'_genesis_hide_title' => true,
'_genesis_hide_breadcrumbs' => true,
'_genesis_hide_singular_image' => true,
],
],
],
$genesis_sample_shared_content['content']
),
'navigation_menus' => $genesis_sample_shared_content['navigation_menus'],
'widgets' => $genesis_sample_shared_content['widgets'],
],
],
],
];
I have modified the onboarding-shared.php file and remove the code for the content Maybe this is the problem?
Update : Now the menu items are created on theme setup. Here's the modified code :
return [
'plugins' => [
[
'name' => __( 'Genesis Blocks', 'genesis-sample' ),
'slug' => 'genesis-blocks/genesis-blocks.php',
'public_url' => 'https://wordpress.org/plugins/genesis-blocks/',
],
],
'navigation_menus' => [
'primary' => [
'get-started' => [
'title' => 'Get Started',
],
'testimonials' => [
'title' => 'Testimonials',
],
'contact' => [
'title' => 'Contact Us',
],
],
],
'widgets' => [
'footer-1' => [
[
'type' => 'text',
'args' => [
'title' => 'Design',
'text' => '<p>With an emphasis on typography, white space, and mobile-optimized design, your website will look absolutely breathtaking.</p><p>Learn more about design.</p>',
'filter' => 1,
'visual' => 1,
],
],
],
'footer-2' => [
[
'type' => 'text',
'args' => [
'title' => 'Content',
'text' => '<p>Our team will teach you the art of writing audience-focused content that will help you achieve the success you truly deserve.</p><p>Learn more about content.</p>',
'filter' => 1,
'visual' => 1,
],
],
],
'footer-3' => [
[
'type' => 'text',
'args' => [
'title' => 'Strategy',
'text' => '<p>We help creative entrepreneurs build their digital business by focusing on three key elements of a successful online platform.</p><p>Learn more about strategy.</p>',
'filter' => 1,
'visual' => 1,
],
],
],
],
];
The menu items aren't for pages, they're linked to scroll points on the homepage. Not sure how to code that using the above PHP?
I removed $genesis_sample_shared_content['content'] and it now works except the menu items aren't created on theme setup maybe due to this error
Notice: Trying to get property 'name' of non-object in wp-admin/nav-menus.php on line 1098
can someone help me, how I can extend an assiociative array with a variable?
I have a loop (foreach):
foreach($this->getWarehouseListForm() as $wareHouse) {
$wareHouseList[] =
[
"title" => "wareHouse[105]",
"form" => [
"storeId[105]" => [
"type" => "inputText",
"options" => [
"name" => "TSL",
],
],
],
];
}
And I want to extend a object like this:
"sections" => [
[
"title" => 'Schuhe24Assistant.ftpServerTitle',
"description" => 'Schuhe24Assistant.ftpServerDescription',
"form" => [
"ftpServer" => [
'type' => 'text',
'defaultValue' => 'ftp.hisasp2.com',
'options' => [
'name' => 'Schuhe24Assistant.ftpServer',
'required' => true,
]
],
"ftpUser" => [
'type' => 'text',
'defaultValue' => 'username',
'options' => [
'name' => 'Schuhe24Assistant.ftpUser',
'required' => true,
]
],
"ftpPassword" => [
'type' => 'text',
'defaultValue' => 'password',
'options' => [
'name' => 'Schuhe24Assistant.ftpPassword',
#'isPassword' => true,
'required' => true,
],
],
"deleteFiles" => [
'type' => 'toggle',
'defaultValue' => true,
'options' => [
'name' => 'Schuhe24Assistant.deleteFiles',
],
],
],
],
], $wareHouseList
But this code produces nothing (no error output) and the structure check fails in this case. If I remove the variable, the structure check is OK.
Can someone help me out?
Kind regards
Henning
Push your $wareHouseList array into the $sections array in the following ways
$sections['wareHouseList'] = $wareHouseList
It should be working.
I have a form that accepts a text field and an image, and I would like to be able to validate or filter the images that are uploaded.
I try to follow this tutorial on GitHub (https://github.com/lowtower/zend-expressive2-tutorial)
I am using zend expressive 2. I have this approach:
<?php
namespace Admin\Model\InputFilter;
use Zend\InputFilter\InputFilter;
class EventoInputFilter extends InputFilter
{
public function init()
{
$this->add([
'name' => 'eventoNombre',
'required' => true,
'filters' => [
['name' => 'StripTags'],
['name' => 'StringTrim'],
],
'validators' => [
[
'name' => 'StringLength',
'options' => [
'min' => 5,
'max' => 100,
],
],
],
]);
$this->add([
'name' => 'imagenes[]',
'required' => true,
'validators' => [
[
'name' => 'FileUploadFile'
],
[
'name' => 'FileMimeType',
'options' => [
'mimeType' => ['image/jpeg', 'image/png']
]
],
[
'name' => 'FileIsImage'
],
[
'name' => 'FileImageSize',
'options' => [
'minWidth' => 128,
'minHeight' => 128,
'maxWidth' => 4096,
'maxHeight' => 4096
]
],
],
'filters' => [
[
'name' => 'FileRenameUpload',
'options' => [
'target' => 'public/eventos/',
'useUploadName' => true,
'useUploadExtension' => true,
'overwrite' => true,
'randomize' => false
]
]
],
]);
}
}
but something is wrong and I do not validate it correctly when I upload a correct image.
I want to make a chart, I have database province and I want to make this be xAxis on Highcharts.
My Database
<?= \dosamigos\highcharts\HighCharts::widget([
'clientOptions' => [
'chart' => [
'type' => 'spline'
],
'title' => [
'text' => 'Fruit Consumption'
],
'xAxis' => [
'categories' => [
'Jabodetabek',
'Banten',
'Jawa Tengah',
'Jawa Timur',
'Medan',
'Riau',
'Bangka Belitung',
'Lampung',
'Kalimantan Selatan',
'Kalimantan Barat',
'Kalimantan Timur',
'Kalimantan Tengah',
'NTB',
'NTT',
'Papua']
],
'yAxis' => [
'title' => [
'text' => 'Fruit eaten'
]
],
'plotOptions' => [
'line' => [
'dataLabels' => [
'enabled'=> true
]
]
],
'series' => [
['data' => [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
],
'responsive' => [
'rules' => [[
'condition' => [
'maxWidth' => 500
],
'charOptions' => [
'legend' => [
'align' => 'center',
'verticalAlign' => 'bottom',
'layout' => 'horizontal'
],
'yAxis' => [
'labels' => [
'align' => 'left',
'x' => 0,
'y' => 0
],
'title' => [
'text' => null
]
]
]
]]
]
]
]);
How can I make the contents of the province table be an array? I want data count all group by provinces.
Please help me
The yii2-friendly method is to use gii to generate models for each of your tables. Then you can get an array like
$provinces = \app\models\Province::find()->select('name')->asArray();
You can use a similar technique to get the count; I'd post an example except I'm not sure what the correct sql would be for your case.
I'm using high-chart extension, but I don't know how to give ID to the container, now getting random id's like yw11,yw12 etc., How to give my own ids to the container like graph1, graph2 etc.,
You have two options:
Change widget id container as states in this line.
Set directly id of container:
$this->Widget('ext.highcharts.HighchartsWidget',array(
'options' =>array(
'chart' => array('renderTo' => $id),
'title' => array('text' => 'title'),
'yAxis' => array(
'title' => array('text' => 'y-values'),
)
)
));
set id to highcharts in yii2 :
echo Highcharts::widget([
'id' => 'YOUR-CUSTOM-ID',
'options' => [
'chart' => [
'type' => 'column',
'margin' => [60, 10, 40, 40],
],
'title' => [
'text' => 'Symmetrical Distribution',
'x' => 25
],
'subtitle' => [
'text' => 'Fisher\'s Iris Data: Sepal Width',
'x' => 25,
],
'legend' => [
'enabled' => false,
],
'credits' => [
'enabled' => false,
],
'tooltip' => [
],
'scripts' => [
'highcharts-more', // enables supplementary chart types (gauge, arearange, columnrange, etc.)
'modules/exporting', // adds Exporting button/menu to chart
'themes/grid' // applies global 'grid' theme to all charts
],
'plotOptions' => [
'series' => [
'pointPadding' => 0,
'groupPadding' => 0.5,
'borderColor' => 'rgba(255,255,255,0.5)',
'color' => '#434348',
]
],
'xAxis' => [
'title' => [
'text' => 'Sepal Width (cm)'
]
],
'yAxis' => [
'title' => [
'text' => ''
]
],
'series' => [
[
'name' => 'Distribution',
'data' => [[2.1, 4], [2.3000000000000003, 7], [2.5, 13], [2.7, 23], [2.9000000000000004, 36], [3.1, 24], [3.3000000000000003, 18], [3.5000000000000004, 10], [3.7000000000000006, 9], [3.9000000000000004, 3], [4.1, 2], [4.300000000000001, 1]]
]
]
]
]);