jaxon-php/jaxon-flot

使用 Flot 库为 Jaxon 创建的 JavaScript 图表

v4.0.0 2022-08-08 08:29 UTC

This package is auto-updated.

Last update: 2024-09-04 00:32:54 UTC


README

使用 Flot 库为 Jaxon 创建的 JavaScript 图表。 http://www.flotcharts.org

安装

使用 Composer 安装此包。

"require": {
    "jaxon-php/jaxon-flot": "~1.0"
}

用法

创建一个新的图表,用于在具有给定 id 的 div 中显示,例如 "flot-container"。

    $plot = $response->flot->plot('#flot-container');

在图表中添加一个图形,并设置其参数。

    $graph = $plot->graph(['label' => 'Plot example', 'lines' => ['show' => true]]);

选项定义在 API 文档中

使用点的数组设置图形数据。

    $graph->series()->points([[0, 3], [4, 8], [8, 5], [9, 13]]);

或一个 JavaScript 表达式。

    $graph->series()->expr(0, 14, 0.5, 'Math.sqrt(x * 10)');

可选,设置 x 轴标签。

    $ticks = [];
    for($i = 0; $i < 10; $i++) $ticks[] = [$i, 'Pt' . $i];
    $plot->xaxis()->points($ticks);

可选,设置图表的尺寸。如果没有在这里设置尺寸,请确保它们在 HTML 或 CSS 代码中。Flot 库要求容器具有宽度和高。

    $plot->width('600px')->height('300px');

最后,绘制图形。

    $response->flot->draw($plot);

您可以在单个图表中添加所需数量的图形,您可以在单个页面上绘制多个图表。

贡献

  • 问题跟踪器:github.com/jaxon-php/jaxon-flot/issues
  • 源代码:github.com/jaxon-php/jaxon-flot

许可证

该项目采用 BSD 许可证。