定制 louisauthie/php2plotly 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

louisauthie/php2plotly

最新稳定版本:1.0.0

Composer 安装命令:

composer require louisauthie/php2plotly

包简介

PlotLy script generation in PHP

README 文档

README

php2plotly is a PHP library that allows you to easily create interactive plots and charts using the Plotly.js library. With php2plotly, you can generate beautiful and dynamic visualizations for your web applications.

Features

  • Support for various chart types, including bar charts, line charts, scatter plots, and more.
  • Seamless integration with Plotly.js for advanced functionality.

Installation

To install php2plotly, simply require the library using Composer:

composer require louisauthie/php2plotly

Usage

Using php2plotly is straightforward. Here's a basic example to get you started:

<?php
namespace App;
require_once __DIR__ . '/../vendor/autoload.php';
use Php2plotly\basic\BarChart;
use Php2plotly\basic\PieChart;
use Php2plotly\basic\ScatterPlot;
use Php2plotly\preprocessor\Preprocessor;
use Php2plotly\stats\BoxPlot;
use Php2plotly\stats\Histogram;
use Php2plotly\scientific\Heatmap;
?>

<html>
    <head>
        <script src="../assets/js/plotly-2.32.0.min.js" charset="utf-8"></script>
    </head>

    <body style="display:flex; flex-wrap:wrap; max-with:100vw;">

    <div id="scatter" style="width:600px;height:400px;"></div>
    <?php
        $scatter = new ScatterPlot('scatter', [
            ['x' => [1, 2, 3, 4], 'y' => [10, 15, 13, 17], 'mode' => 'markers'],
            ['x' => [2, 3, 4, 5], 'y' => [16, 5, 11, 9], 'mode' => 'lines']
        ]);
        echo '<script>'.$scatter->render().'</script>';

    ?>

    <div id="bar" style="width:600px;height:400px;"></div>

    <?php
        $bar = new BarChart('bar', ['x' => ["Cat1", "Cat2", "Cat3", "Cat4"], 'y' => [10, 15, 13, 17]]);
        echo '<script>'.$bar->render().'</script>';
    ?>

    <div id="pie" style="width:600px;height:400px;"></div>
    <?php
        $pie = new PieChart('pie', ['values' => [10, 15, 13, 17], 'labels' => ["Cat1", "Cat2", "Cat3", "Cat4"],'textinfo'=>'label+percent','insidetextorientation'=>'radial'], ['height' => 400, 'width' => 600]);
        echo '<script>'.$pie->render().'</script>';
    ?>

    <div id="histogram" style="width:600px;height:400px;"></div>
    <?php
        $histogram = new Histogram('histogram', ['x' => [1, 2, 3, 4]]);
        echo '<script>'.$histogram->render().'</script>';
    ?>

    <div id="bplot" style="width:600px;height:400px;"></div>
    <?php
        $listsBoxPlot  = [
            ['y' => [1, 2, 3, 4, 5, 8, 10, 40, 0, -8]],
            ['y' => [1, 2, 3, 4, 5, 8, 10, 40, 0, -8]],
            ['y' => [1, 2, 3, 4, 5, 8, 10, 40, 0, -8]],
            ['y' => [1, 2, 3, 4, 5, 8, 10, 10, 0, -7]],
            ['y' => [1, 2, 3, 4, 5, 8, 10, 10, 0, -7]],
        ];
        $boxplot = new BoxPlot('bplot', $listsBoxPlot);
        echo '<script>'.$boxplot->render().'</script>';
    ?>

    <div id="heatmap" style="width:600px;height:400px;"></div>
    <?php
        $heatmap = new Heatmap('heatmap', 
            ['x' => ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], 'y' => ['Morning', 'Afternoon', 'Evening'], 'z' => [[1, 0, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, -10, 20]]]
        );
        echo '<script>'.$heatmap->render().'</script>';
    ?>

    <div id="countHistog" style="width:600px;height:400px;"></div>
    <?php
        $values= [1.2,1.4, 2, 3, 7, 4, 4, 4, 4, 4.5, 4, 4];
        $histogram = new BarChart('countHistog', Preprocessor::countNumberByInterval($values, 3));
        echo '<script>'.$histogram->render().'</script>';
    ?>
    </body>
</html>

Contributing

Contributions are welcome! If you have any bug reports, feature requests, or pull requests, please open an issue on the GitHub repository.

License

php2plotly is licensed under the MIT License. See LICENSE for more information.

统计信息

  • 总下载量: 35
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-06-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固