【问题标题】:I can't change the legend position in Laravel Charts & ChartJS我无法更改 Laravel 图表和 ChartJS 中的图例位置
【发布时间】:2020-03-12 12:50:38
【问题描述】:

我在 ChartJS 中使用 Laravel Charts (https://charts.erik.cat/),但遇到了问题。我无法更改图表中的标签位置。

我已尝试以下方法,但我的标签仍位于顶部。我还尝试使用工具提示复制文档中的示例,但这也不起作用。 backgroundColor 函数出于某种原因起作用。

    $typeChart->dataset('Aantal', 'pie', [$countCustomers, $countProspects, $countColdLeads, $countHotLeads])
            ->options([
                'backgroundColor' => 'green',
                'displayLegend' => true,
                'legend' => [
                    'position' => 'right',
                    'align' => 'right',
                    'display' => true
                ],
                'tooltip' => [
                    'show' => false
                ]
            ]);
    //        $typeChart->options([
    //            'tooltip' => [
    //                'show' => true // or false, depending on what you want.
    //            ],
    //        ]);

【问题讨论】:

    标签: laravel chart.js


    【解决方案1】:

    我遇到了同样的问题 - 我无法使用“选项”方法传递一些配置。

    我解决了这个问题,将我自己的方法添加到 UserChart 类中

    namespace App\Charts;
    
    use ConsoleTVs\Charts\Classes\ChartJs\Chart;
    
    class UserChart extends Chart
    {
        /**
         * Initializes the chart.
         *
         * @return void
         */
        public function __construct()
        {
            parent::__construct();
        }
        
        public function legendPosition(string $position)
        {
            return $this->options([
                'legend' => [
                    'position' => $position,
                ],
            ]);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2022-11-03
      • 1970-01-01
      • 2021-02-01
      • 2013-06-29
      • 1970-01-01
      • 1970-01-01
      • 2019-07-08
      • 2020-04-17
      • 2018-02-08
      相关资源
      最近更新 更多