gsferro/chartsexcell

该包的最新版本(v1.3)没有可用的许可证信息。

使用Laravel Excel包轻松创建图表的Facade

v1.3 2021-01-18 14:29 UTC

This package is auto-updated.

Last update: 2024-09-18 22:46:17 UTC


README

这是一个用于在Excel中简化图表创建的包,因为即使包本身的文档也没有提及图表的实现,更不用说在互联网上找到实现方法。

安装

composer require gsferro/chartsexcell

依赖关系

maatwebsite/excel": "^3.1

将以下内容放置在app.php文件中

  • 提供者
Maatwebsite\Excel\ExcelServiceProvider::class,
  • 别名
'Excel' => Maatwebsite\Excel\Facades\Excel::class,

使用方法

  • 初始化
$createChart = chartsexcell();

一般参数

  • 布局
/**
 * Possibilidade de mudar o layout do gráfico
 *
 * @param Layout $layout
 * @return ChartsExcell
 */
 ->setLayout(Layout $layout) // default: null
  • 显示百分比

    ->setLayout((new Layout())->setShowPercent(true))

  • 显示值

    ->setLayout((new Layout())->setShowVal(true))

  • 图例

/**
 * Possibilidade de mudar a Legend
 *
 * @param Legend $legend
 * @return ChartsExcell
 */
->setLegend(Legend $legend = null) // default: new Legend('r')
  • 无图例

->setLegend(null)

  • 图例在右侧

->setLegend((new Legend('r'))

  • 图例在左侧

->setLegend((new Legend('l'))

  • 图例在底部

->setLegend((new Legend('b'))

  • 图例在顶部

->setLegend((new Legend('t'))

  • 图例在右上角

->setLegend((new Legend('tr'))

  • 一般信息
/**
 * Cabelhaço do excell
 * Adicionar +1 no $index para buscar os valores
 *
 * @param int $linesHeader
 * @return ChartsExcell
 */
->setLinesHeader(int $linesHeader) // default 1
/**
 * Posição para começar a busca pelos dados
 *
 * @param int $index
 * @return ChartsExcell
 */
->setIndex(int $index) // default 2
/**
 * Titulo da aba - (Não pode ter espaços)
 *
 * @param string $titleSheet
 * @return ChartsExcell
 */
->setTitleSheet(string $titleSheet) // default: "Worksheet"
/**
 * Tipo do chart via DataSeries const
 *
 * @param string $typeChart DataSeries::TYPE_PIECHART / pieChart
 * @return ChartsExcell
 */
->setTypeChart(string $typeChart) // default: DataSeries::TYPE_PIECHART / pieChart

图表数据

/**
 * Monta o grafico
 *
 * @param string $title       "Titulo do gráfico"
 * @param int $countLines     "Qtde linhas de registro"
 * @param string $columnLabel "Letra da Coluna para os labels do chart"
 * @param string $columnValue "Letra da Coluna para os valores do chart"
 *
 * @return Chart
 */
->chart(string $title, int $countLines, string $columnLabel, string $columnValue) : Chart