Giter Club home page Giter Club logo

yii2-chartjs-widget's People

Contributors

leon4m avatar pana1990 avatar tonydspaniard avatar tsanchev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-chartjs-widget's Issues

Properties of chart inaccesible

$view->registerJs($js);

When registering clientScript the default context is View::POS_READY, that wraps all the javascript in a jquery function and makes it inaccesible.

If you are rendering many views in a component with renderPartial you will not be able to access javascript chart object in the browser..

Changing it to View::POS_END can solve this problem.
Or maybe adding a parameter to change script position on demand.

Want you add it?

   public function colorsRand($data){

        $keys = array_keys($data);

        for( $i=0 ; $i < count($keys) ; $i++ )
        {
            $keys[$i] = "rgb(" . rand(100, 200) . "," . rand(100, 200) . "," . rand(100, 200) . ")";
        }
        return $keys;
    }

its randomization if no color init. $data - is array values

ChartJs::widget([
            'type' => 'pie',
            'options' => [
                'id' => 'mychart',
                'class' => 'chartContainer-'.Yii::$app->security->generateRandomString(rand(5,10)),
                'height' => 100,
                'width' => 200
            ],
            'data' => [
                'labels' => $labels,
                'datasets' => [
                    [
                        'label' => "My First dataset",
                        'backgroundColor' => $this->colorsRand($data),
                        'data' => $data
                    ],
                ]
            ]

        ]);

Applying callback functions

I have this bar chart, just a standard one and I want to modify how yAxes labels are showing without decimals, however I have this weird thing going on. Here's my config options. Can you explain why is this happening & what is the possible workaround for this? Thank you.

'clientOptions' => [
                    'scales' => [
                        'yAxes' => [[
                            'ticks' => [
                                'beginAtZero' => 'true', # Works
                                'callback' => function($label, $index, $labels) { // Breaks.
                                    if (floor($label) === $label) return $label;
                                }
                                # Console : TypeError: ({}) is not a function[Learn More] ???
                                # Errors  : TypeError: element._view is undefined ???
                            ]
                        ]],
                    ],
                ], 

CharJS v2 properties changed.

properties change in version 2 of ChartJS, the correction should be performed in the README to avoid confusion.

datasets: [
        {
            label: "My First dataset",
            backgroundColor: "rgba(179,181,198,0.2)",
            borderColor: "rgba(179,181,198,1)",
            pointBackgroundColor: "rgba(179,181,198,1)",
            pointBorderColor: "#fff",
            pointHoverBackgroundColor: "#fff",
            pointHoverBorderColor: "rgba(179,181,198,1)",
            data: [65, 59, 90, 81, 56, 55, 40]
        },
        {
            label: "My Second dataset",
            backgroundColor: "rgba(255,99,132,0.2)",
            borderColor: "rgba(255,99,132,1)",
            pointBackgroundColor: "rgba(255,99,132,1)",
            pointBorderColor: "#fff",
            pointHoverBackgroundColor: "#fff",
            pointHoverBorderColor: "rgba(255,99,132,1)",
            data: [28, 48, 40, 19, 96, 27, 100]
        }
    ]

I have today this error

Setting unknown property: dosamigos\chartjs\ChartJs::plugins by PieChart

in the Chart class there is no attribute named plugins, but in the documentation there is an example with "plugins".

any idea??

legend

Hello,

Do you have a example of code to customize a legend in this new version ?

great job
thz

The file or directory to be published does not exist

Hi, thanks for the plugin. I have installed it via the composer. Now when I am trying to view a basic sample of the chart. It's giving me an error.

ChartJs::widget([ 'type' => 'line', 'options' => [ 'height' => 400, 'width' => 400 ], 'data' => [ 'labels' => ["January", "February", "March", "April", "May", "June", "July"], 'datasets' => [ [ 'label' => "My First dataset", 'backgroundColor' => "rgba(179,181,198,0.2)", 'borderColor' => "rgba(179,181,198,1)", 'pointBackgroundColor' => "rgba(179,181,198,1)", 'pointBorderColor' => "#fff", 'pointHoverBackgroundColor' => "#fff", 'pointHoverBorderColor' => "rgba(179,181,198,1)", 'data' => [65, 59, 90, 81, 56, 55, 40] ], [ 'label' => "My Second dataset", 'backgroundColor' => "rgba(255,99,132,0.2)", 'borderColor' => "rgba(255,99,132,1)", 'pointBackgroundColor' => "rgba(255,99,132,1)", 'pointBorderColor' => "#fff", 'pointHoverBackgroundColor' => "#fff", 'pointHoverBorderColor' => "rgba(255,99,132,1)", 'data' => [28, 48, 40, 19, 96, 27, 100] ] ] ] ]);

Error

The file or directory to be published does not exist: F:\xampp\htdocs\mdc/vendor\bower/chartjs/dist

Note: I am using yii2

Cannot Install The Widget

I got error, when i tried to Install , this Widget.

Problem 1
- Installation request for 2amigos/yii2-chartjs-widget dev-master -> satisfiable by 2amigos/yii2-chartjs-widget[dev-master].
- 2amigos/yii2-chartjs-widget dev-master requires bower-asset/chartjs 1.0.2 -> no matching package found.

Potential causes:

Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

How do I solve this problem?

chartjs-plugin-annotation

Any chance to get something like chartjs-plugin-annotation bundled with yii2-chartjs-widget?
Thank you!

EDIT:
For those who needs this, I've already achieved this by:

  • requiring "bower-asset/chartjs-plugin-annotation": "*", in composer.json
  • inheriting AssetBundle to ChartJsAnnotationAsset (see ChartJsAsset.php)
  • calling ChartJsAnnotationAsset::register($this); in the target view

Problem with the example in the docs

Hi,
First of all I would like to say thank you for this useful widget.
There is a tiny problem in you example. It seems that you are using JSON instead of PHP array.

Here is my fix:

<?= ChartJs::widget([
    'type' => 'line',
    'options' => [
        'height' => 400,
        'width' => 400
    ],
    'data' => [
        'labels' => ["January", "February", "March", "April", "May", "June", "July"],
        'datasets' => [
            [
                'label' => "My First dataset",
                'backgroundColor' => "rgba(179,181,198,0.2)",
                'borderColor' => "rgba(179,181,198,1)",
                'pointBackgroundColor' => "rgba(179,181,198,1)",
                'pointBorderColor' => "#fff",
                'pointHoverBackgroundColor' => "#fff",
                'pointHoverBorderColor' => "rgba(179,181,198,1)",
                'data' => [65, 59, 90, 81, 56, 55, 40]
            ],
            [
                'label' => "My Second dataset",
                'backgroundColor' => "rgba(255,99,132,0.2)",
                'borderColor' => "rgba(255,99,132,1)",
                'pointBackgroundColor' => "rgba(255,99,132,1)",
                'pointBorderColor' => "#fff",
                'pointHoverBackgroundColor' => "#fff",
                'pointHoverBorderColor' => "rgba(255,99,132,1)",
                'data' => [28, 48, 40, 19, 96, 27, 100]
            ]
        ]
    ]
]);
?>

Can't able to add jsEvents (onClick)

I'm trying to add onClick function on chart but it throws error
Setting unknown property: dosamigos\chartjs\ChartJs::jsVar

Here is code,
ChartJs::widget([
'type' => 'bar',
'jsVar' => 'BarChart',
'jsEvents' => [
'onclick' => new JsExpression('function(e) {
var activePoints = BarChart.getElementsAtEvent(e);
if (activePoints !== undefined && activePoints[0] !== undefined && activePoints[0]._index !== undefined) {
var selectedIndex = activePoints[0]._index;
console.log(this.data.labels[selectedIndex]);
}
}')
],
......

how can change the tooltip point style?

2022_11_17_11_46_50_Greenshot

How can i change the point style in the tooltip? Or how can i disable this one?

return ChartJs::widget([ 'type' => 'line', 'id' => 'durations', 'options' => [ 'maintainAspectRatio'=> false, 'responsive' => true, 'plugins' => [ 'tooltip' => [ 'usePointStyle' => false, ], ] ],
This is my code like the infos from chart.js website. But this not will working with the widget. I hope anybody can help me.

Fatal error "The file or directory to be published does not exist: /vendor/bower-asset/chartjs/dist"

Hi, I've just installed your great plugin via composer! Using "composer require 2amigos/yii2-chartjs-widget:~2.0" (maybe the error should be also in the main page of plugin, where there's wrote version ~2.0) and it was installed correctly. I've try to put your demo code to display a first chart just for example, but it doesn't work :( (I've also tried with "2amigos/yii2-chartjs-widget": "dev-master").

Schermata 2020-02-27 alle 15 06 58

but if I visit the page I got this error:

Schermata 2020-02-27 alle 15 05 09

I've read in the other topics that is should fixed on new version 3.0, but I don't care why doesn't work :( #44
Could you kindly help me please?
The only way I found to got it working is follow this reply to that issue: #44 (comment)

Many thanks & best regards,
Chris

directory to be published does not exist: chartjs/dist

In the latest release dev-master charts js no more includes the dist folder, so an error is thrown when using the widget:

Invalid Argument – yii\base\InvalidArgumentException
The file or directory to be published does not exist: /shared/httpd/project/vendor/bower-asset/chartjs/dist

Type doughnut & options

After upgrade chartjs to latest version I have problem with defining width and height of chart.

$chart = ChartJs::widget([ 'type' => 'doughnut', 'options' => [ 'id' => 'cstat', 'cutoutPercentage' => 25, 'legend' => [ 'display' => false], 'height' => 150, 'width' => 150 ], 'data' => $dt, ]);

I see that options: cutoutPercentage, height, width not works. Is there any problems or I have to do it in other way?

Chart.js bower version

Hi,
I need to test some functionalities provided in the master branch of chart.js library.
As I see in the yii2-chartjs-widget master branch, the composer file it is pointing to a specific release (1.0.2). I think this master branch should be using * and let the developer decide to specify a version (or not).
If you make a release of this extension you could use the specified version (or not) but master should be using *. It is the development branch.

What do you think about this approach? Do you think it make sense?

text in the middle of a doughnut

Hi everybody,

how can i add a text in the middle of a doughnut? I think i must do this with plugins, but don't know how the best practice.

Now i found a solution. You should really read the documentation first :-)

It works fine. But if i have a doughnut with a legend left or right, the text always shown in the middle of the canvas, but not in the middle of the doughnut.

grafik

This is my code:

` 'plugins' =>

                new \yii\web\JsExpression('
                [{
                    id: \'text\',
                    beforeDraw: function(chart, a, b) {
                        var width = chart.width,
                        height = chart.height,
                        ctx = chart.ctx;
                        ctx.restore();
                        var fontSize = (height / 50).toFixed(2);
                        ctx.font = fontSize + "em sans-serif";
                        ctx.textBaseline = "middle";
                        ctx.fillStyle ="rgb(200,200,200)";
            
                        var text = "'.$numVal.'",
                        textX = Math.round((width - ctx.measureText(text).width) / 2),
                        textY = height / 2;
            
                        ctx.fillText(text, textX, textY);
                        ctx.save();
                    }
                }]'),                

`

I hope ones of you has a tip for me.

Thanks very much...

How user this plugin? [renderPartial]

How can i use this plugin without layout rendering?
My data loads by ajax and renderPartial in controller.

If i use thi plug in normal mode(default render) - all is ok!

Can you change to see legend

Hi,

In line 96 I put this:
$js .= "document.getElementById('chartLegend_{$id}').innerHTML = chartJS_{$id}.generateLegend();";

and i view this:

and I see the legend. Can you do this in your version?

New version of Chartjs

Hi guys,
Are you planning any updates to chartjs version? The difference is quite big at the moment

Accessing Chart from another script

Hello,
is it possible to access the Chart from different script?

I would like to add checkboxes to show/hide datasets in multiple dataset pie.

I can see that in registerClientScript() there is initialization of the Chart chartJS_{$id} = new Chart($('#{$id}'),{$config});,
I can see in my app, that it is filled with chartJS_w3,
but when I try to use it I get an error Uncaught ReferenceError: chartJS_w3 is not defined.

This is my code:

<script>
        function updateChart(data) {
            console.log(chartJS_w3);
            const isDataShown = chartJS_w3.isDatasetVisible(data.value);
            if (isDataShown === true) {
                chartJS_w3.hide(data.value);
            }
            if (isDataShown === false) {
                chartJS_w3.show(data.value);
            }
        }
</script>

I found something similar to what I need at different package

You can access the JavaScript chart object from another script like this:
var chart = $('#my-chart-id').highcharts();

The chart title could not be displayed

I'm trying to view the chart title by setting the following options

'Legend' => [
'Display' => false
]
'Title' => [
'display' => true,
'text' => 'COST OF SERVICES',
'Position' => 'bottom'
]

but it does not work

Use it with Pjax

Hello, can this widget loaded with Pjax feature? i want add a custom filter, so the chart will be changed based on my click button.

Thanks..

Callbacks

I can't make callbacks for tooltips...

Any can help?

options: {            
        tooltips: {
            callbacks: {
                label: function(tooltipItems, data) {
                    return data.datasets[tooltipItems.datasetIndex].label +': ' + tooltipItems.yLabel + ' €';
                }
            }

        }
    }`

Configuring options for multiple datasets

Hi, thanks for your plugin. I am having some problems configuring my chart options. I am doing a chart with multiple datasets. The first is a bar chart and then on each bar I need to display a data point, see attached image. I display the points as the second dataset with 'type' => 'line'. The problem i am having is that I want to configure the line dataset differently than the bar chart, specifically I want to disable tooltips for the bar chart and only enable them for the line chart. I can disable for both using `clientOptions' but I can't seem to disable them individually. See example below. Any suggestions on configuring options for multiple datasets?

'type' => 'bar',
        'options' => [
            'height' => 400,
            'width' => 400
        ],
        'clientOptions' => [
            'title' => [
                'display' => true,
                'fontColor' => $domain->primary_color,
                'fontSize' => 20,
                'text' => $domain->name,
                'position' => 'top'
            ],
            'legend' => [
                'display' => false,
                'position' => 'bottom'
            ],
            'scales' => [
                'yAxes' => [[
                    'ticks' => [
                        'min' => 0,
                        'suggestedMax' => 5
                    ]]
                ]
            ],
            'tooltips' => [  
                    'enabled' => true // <-- This works, but for both datasets   
            ]
        ],
        'data' => [
            'labels' => $labels,
            'datasets' => [
                [
                    'label' => "Bar Chart label",
                    'backgroundColor' => $domain->barColor(),
                    'borderColor' => $domain['primary_color'],
                    'pointBackgroundColor' => "rgba(179,181,198,1)",
                    'pointBorderColor' => "#fff",
                    'pointHoverBackgroundColor' => "#fff",
                    'pointHoverBorderColor' => "rgba(179,181,198,1)",
                    'data' => $data,
                    'tooltips' => [  
                        'enabled' => true // <-- This works, but for both datasets   
                    ]
                ],
                [
                    'label' => 'Marker label',
                    'type' => 'line',
                    'data' => $markers,
                    'pointRadius' => 6,
                    'showLine' => false,
                    'pointStyle' => 'point',
                    'pointBackgroundColor' => "rgb(0,0,0)",
                    'tooltips' => [
                        'enabled' => true // When I try to set options here they don't take effect
                    ]
                ]
            ]
        ]

This is what I am trying to achieve.
Screen Shot 2020-04-07 at 11 45 45 AM

What I got so far, the tooltip does not line up with the point and it show both the labels, I just want the Marker label and it to only appear when hovering over the marker.
Screen Shot 2020-04-07 at 11 47 01 AM

Legend options

Hi,
How can I set legend options like?

legend:{
display: true,
position: 'bottom',
fullWidth:true,
labels:{
boxWidth:30 //Width legend colorbox
}
}

Chart not showing on view screen

Hi,

My chart is not showing on my view screen. There is a space where the chart should show but it doesn't.

In my script I also have a Highchart chart working.

  • Andrew
<?php

use yii\helpers\Html;
use dosamigos\chartjs\ChartJs;
use miloschuman\highcharts\Highcharts;

?>

<div class="contract-index">
    <?= Highcharts::widget([
            'options' => [
                'chart' => ['type' => 'bar'],
               '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]]
               ]
            ]
    ]); ?>   
    
    
    <?= ChartJs::widget([ 'type' => 'Line', 'options' => 
                        [ 'height' => 400, 'width' => 400 ], 
                        'data' => 
                            [ 'labels' => ["January", "February", "March", "April", "May", "June", "July"], 
                                'datasets' => [ 
                                    [   'fillColor' => "rgba(220,220,220,0.5)", 
                                        'strokeColor' => "rgba(220,220,220,1)", 
                                        'pointColor' => "rgba(220,220,220,1)", 
                                        'pointStrokeColor' => "#fff", 'data' => [65, 59, 90, 81, 56, 55, 40] ], 
                                    [ 'fillColor' => "rgba(151,187,205,0.5)", 
                                      'strokeColor' => "rgba(151,187,205,1)", 
                                      'pointColor' => "rgba(151,187,205,1)", 
                                      'pointStrokeColor' => "#fff", 
                                      'data' => [28, 48, 40, 19, 96, 27, 100] 
                                    ] 
                                    
                                ] 
                            ] 
                        ]); ?>     
</div>

image

how to set options for line chart?

Hello! Not work scales options. What am I doing wrong?

ChartJs::widget([
    'type' => 'line',
     'options' => [
         'height' => 70,
         'width' => 400,
         'scales' => [
             'yAxes' => [
                 'ticks' => [
                     'min' => 0
                 ]
             ],
             'xAxes' => [
                 'ticks' => [
                     'min' => 0
                 ]
             ]
     ]
], 'data' => []

100% width

How can I apply a 100% width to the chart, eg. to take the width from a surrounding bootstrap container?

Maintainer Help Required

Due to the busy schedule I have, I cannot longer maintain our Yii open source libraries. I am looking for a maintainer of the library as I don't want to deprecate the library if its of any use to somebody.

Let me know in this thread those interested. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.