Title: Greencharts
Author: mbaroncini
Published: <strong>2023 年 2 月 14 日</strong>
Last modified: 2023 年 2 月 14 日

---

搜尋外掛

這個外掛**並未在最新的 3 個 WordPress 主要版本上進行測試**。開發者可能不再對這個
外掛進行維護或提供技術支援，並可能會與更新版本的 WordPress 產生使用上的相容性問題。

![](https://ps.w.org/greencharts/assets/icon.svg?rev=2865055)

# Greencharts

 由 [mbaroncini](https://profiles.wordpress.org/mbaroncini/) 開發

[下載](https://downloads.wordpress.org/plugin/greencharts.1.0.1.zip)

 * [詳細資料](https://tw.wordpress.org/plugins/greencharts/#description)
 * [使用者評論](https://tw.wordpress.org/plugins/greencharts/#reviews)
 *  [安裝方式](https://tw.wordpress.org/plugins/greencharts/#installation)
 * [開發資訊](https://tw.wordpress.org/plugins/greencharts/#developers)

 [技術支援](https://wordpress.org/support/plugin/greencharts/)

## 外掛說明

This WordPress plugin allows you to easily add interactive charts to your website,
using data from the global-warming.org API and the ChartJs library. The plugin has
built-in mechanisms such as server cache, lazy load and client cache, which work
together to reduce the CO2 emissions caused by internet/hardware usage per chart
view.

### Usage

Once the plugin is installed and configured, you can add chart shortcodes to your
pages and posts. The available shortcodes are:

 * `[greencharts-chart type="temperature"]`: Displays a line chart of global temperature
   change over time.
 * `[greencharts-chart type="co2"]`: Displays a line chart of CO2 emissions by country.
 * `[greencharts-chart type="methane"]`: Displays a line chart of global methane
   gas emissions.
 * `[greencharts-chart type="oceanwarming"]`: Displays a line chart of global ocean
   warming.

You can customize the appearance of the charts using the ChartJs library’s options
and callbacks using wordpress js hooks. Visit [ChartJs documentation](https://www.chartjs.org/docs/latest/)
for more information.

### Support

If you have any issues with the plugin, please open a Github issue or contact us
via email. We will do our best to assist you.

### Contribution

If you would like to contribute to the development of this plugin, please fork the
repository and submit a pull request.

### Disclaimer

This plugin is provided “as is” without warranty of any kind, either express or 
implied. Global warming.org and ChartJs library do not endorse this plugin and are
not responsible for any damages or losses that may result from its use.

### Plugin hooks

#### php [docs](https://developer.wordpress.org/plugins/hooks/)

Use the apply_filters function to set a transient value to false. This will disable
caching for the greencharts data.

    ```
    apply_filters('greencharts_transient_disableCache', false);
    ```

Use the apply_filters function to set the lifespan of transient. The filter can 
be used to modify the lifespan of the transient before it is set. The transient 
is used to cache remote API requests, default transient is 1 month. The lifespan
should be the number of seconds, see [$expiration](https://developer.wordpress.org/reference/functions/set_transient/#parameters)
parameter of wordpress `set_transient` function

    ```
    apply_filters('greencharts_transient_lifespan', $this->lifespan, $this);
    ```

Use the apply_filters function to set a logger value to true. This will enable logging
for the greencharts data.

    ```
    apply_filters('greencharts_logger_shouldLog', defined('WP_DEBUG') && true === WP_DEBUG);
    ```

Use the apply_filters function to set a verbose value to true. This will enable 
verbose logging for the greencharts data.

    ```
    apply_filters('greencharts_logger_shouldBeVerbose', false);
    ```

Uses the apply_filters function to alter ajax resposes data used by charts. Useful
if you need to add more charts.

    ```
    apply_filters('greencharts_ajax_chartsApi',$charts->getChartsDataByType($type), $type);
    ```

#### js [docs](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-hooks/)

Remember to use `wp.hooks.addFilter` BEFORE greencharts js load.

This code applies a filter to the chartConfig object which is used to create a greencharts_js_chartConfig
chart on the canvas. The filter is used to modify the chartConfig object so that
it can be used to create a customized chart.

    ```
    globalHooks.applyFilters("greencharts_js_chartConfig", chartConfig, canvas);
    // usage example:
    wp.hooks.addFilter(
      "greencharts_js_chartConfig",
      "defaultHooks",
      (chartConfig, canvas) => {
        console.log("THEME FILTER", chartConfig, canvas.dataset.type);
        chartConfig.data.datasets[0].backgroundColor = "blue";
        return chartConfig;
      }
    );
    ```

This code applies a filter to the debug var that control operations logging. The
filter is set to false, meaning that any code related to greencharts_js_debug will
not be logged in the browser js console.

    ```
    globalHooks.applyFilters("greencharts_js_debug", false),
      // usage example:
      wp.hooks.addFilter("greencharts_js_debug", "defaultHooks", () => true);
    ```

This code applies a filter to the “greencharts_js_errorMessage” string. The filter
takes in the string, along with the data and error objects, and returns a modified
version of the string. This is useful for customizing error messages based on different
scenarios.

    ```
    globalHooks.applyFilters(
      "greencharts_js_errorMessage",
      "Something goes wrong during chart loading. Please retry later",
      data,
      error
    );
    ```

This code applies a filter to the text of a “Reset zoom” button on a canvas element.
This allows developers to customize the text of the button.

    ```
    options.globalHooks.applyFilters(
      "greencharts_js_resetZoomButtonText",
      "Reset zoom",
      canvas
    );
    ```

This code applies a filter to the text of a “Load chart” button on a canvas element.
This allows developers to customize the text of the button.

    ```
    options.globalHooks.applyFilters(
      "greencharts_js_loadButtonText",
      "Load chart",
      canvas
    );<h3>Assets attribution</h3>
    ```

– Image by (rawpixel.com)[https://www.freepik.com/free-vector/social-media-analysis-
design-graphs_16323246.htm#query=minimal%20charts&position=3&from_view=search&track
=ais] on Freepik
 – Image by (Freepik)[https://www.freepik.com/free-vector/green-
energy-buildings_713297.htm#query=eco%20green&position=31&from_view=search&track
=ais]

## 螢幕擷圖

 * [[
 * The button viewed before chart load
 * [[
 * The zoomed CO2 chart
 * [[
 * The entire CO2 chart
 * [[
 * The ocean warming chart
 * [[
 * The methane levels chart
 * [[
 * The temperature chart

## 安裝方式

 * Download the plugin from the WordPress plugin repository.
 * Upload the plugin to your website and activate it.

## 使用者評論

這個外掛目前沒有任何使用者評論。

## 參與者及開發者

以下人員參與了開源軟體〈Greencharts〉的開發相關工作。

參與者

 *   [ mbaroncini ](https://profiles.wordpress.org/mbaroncini/)

[將〈Greencharts〉外掛本地化為台灣繁體中文版](https://translate.wordpress.org/projects/wp-plugins/greencharts)

### 對開發相關資訊感興趣？

任何人均可[瀏覽程式碼](https://plugins.trac.wordpress.org/browser/greencharts/)、
查看 [SVN 存放庫](https://plugins.svn.wordpress.org/greencharts/)，或透過 [RSS](https://plugins.trac.wordpress.org/log/greencharts/?limit=100&mode=stop_on_copy&format=rss)
訂閱[開發記錄](https://plugins.trac.wordpress.org/log/greencharts/)。

## 變更記錄

 * 1.0.1
    Updated README
 * 1.0.0
    The first stable version
 * 0.1
    The first beta version

## 中繼資料

 *  版本 **1.0.1**
 *  最後更新 **3 年前**
 *  啟用安裝數 **少於 10 次**
 *  WordPress 版本需求 ** 5.0 或更新版本 **
 *  已測試相容的 WordPress 版本 **6.1.10**
 *  PHP 版本需求 ** 7.0 或更新版本 **
 *  語言
 * [English (US)](https://wordpress.org/plugins/greencharts/)
 * 標籤:
 * [ChartJS](https://tw.wordpress.org/plugins/tags/chartjs/)[charts](https://tw.wordpress.org/plugins/tags/charts/)
   [Green](https://tw.wordpress.org/plugins/tags/green/)
 *  [進階檢視](https://tw.wordpress.org/plugins/greencharts/advanced/)

## 評分

這個項目尚無任何評論記錄。

[Your review](https://wordpress.org/support/plugin/greencharts/reviews/#new-post)

[查看全部使用者評論](https://wordpress.org/support/plugin/greencharts/reviews/)

## 參與者

 *   [ mbaroncini ](https://profiles.wordpress.org/mbaroncini/)

## 技術支援

使用者可在技術支援論壇提出意見反應或使用問題。

 [檢視技術支援論壇](https://wordpress.org/support/plugin/greencharts/)