Easy Charts Shortcode

Below, you’ll find a detailed guide on how to add the Easy Charts Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Easy Charts Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Easy Charts Plugin and the shortcodes it provides:

Plugin Icon
Easy Charts

"Easy Charts is a user-friendly WordPress plugin that simplifies the creation and customization of interactive and responsive charts on your website."

★★★★☆ (11) Active Installs: 3000+ Tested with: 6.2.3 PHP Version: false
Included Shortcodes:
  • [easy_chart]

Easy Charts [easy_chart] Shortcode

The Easy_Charts shortcode is a dynamic tool that embeds a specific chart within your WordPress content. Upon execution, it calls the ‘easy_chart_shortcode_callback’ function, passing chart_id as an attribute. If a valid chart_id is provided, it triggers the Easy_Charts plugin and enqueues necessary scripts for chart rendering. The chart specified by the chart_id is then displayed.

Shortcode: [easy_chart]

Parameters

Here is a list of all possible easy_chart shortcode parameters and attributes:

  • chart_id – The unique identifier of the chart to be displayed

Examples and Usage

Basic example – Display a chart by specifying the chart ID

[easy_chart chart_id=1 /]

Advanced examples

Creating a chart by specifying multiple chart IDs. This will display multiple charts on your page.

[easy_chart chart_id=1 /]
[easy_chart chart_id=2 /]
[easy_chart chart_id=3 /]

Remember, the shortcode will only work if the chart ID specified exists. If the chart ID does not exist, the shortcode will return an empty string and no chart will be displayed.

PHP Function Code

In case you have difficulties debugging what causing issues with [easy_chart] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'easy_chart', array( $this, 'easy_chart_shortcode_callback' ) );

Shortcode PHP function:

function easy_chart_shortcode_callback( $atts, $content = '' ) {
		$atts = shortcode_atts( array(
			'chart_id' => null,
		), $atts, 'easy_chart' );

		$chart_id = $atts['chart_id'];

		if ( $chart_id ) {
			$plugin = new Easy_Charts();

			wp_enqueue_script( 'easy-charts-public-js' );

			wp_enqueue_script( 'd3-js' );

			wp_enqueue_script( 'uvhcharts-js' );

			wp_enqueue_script( 'filesaver-js' );

			wp_enqueue_script( 'canvg-js' );

			wp_enqueue_script( 'canvas-toblob-js' );

			return $plugin->ec_render_chart( $chart_id );
		}

		return '';
	}

Code file location:

easy-charts/easy-charts/public/class-easy-charts-public.php

Conclusion

Now that you’ve learned how to embed the Easy Charts Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *