A custom ACF block for WordPress themes that lets editors create and display interactive charts. Built with Advanced Custom Fields PRO and Chart.js.
- WordPress 6.0 or higher
- Advanced Custom Fields PRO 6.0 or higher
- A WordPress theme
- Copy the
dynamic-chart
folder into your theme'sblocks
directory:
themes/your-theme/
└── blocks/
└── dynamic-chart/
- Add this code to your theme's
functions.php
:
function register_acf_blocks() {
register_block_type( get_template_directory() . '/blocks/dynamic-chart' );
wp_enqueue_script(
'chartjs',
'https://cdn.jsdelivr.net/npm/chart.js',
array(),
'3.7.0',
true
);
}
add_action( 'init', 'register_acf_blocks' );
- In WordPress admin, go to Custom Fields → Add New
- Import the included ACF field group or create fields manually following the structure in the Field Configuration section below
- Multiple chart types (bar, line, pie, radar)
- Manual data entry with color picker
- CSV data upload
- Customizable settings (title, legend, animations)
- Live preview in the editor
- Create or edit a post/page
- Add the "Dynamic Chart" block
- Choose your chart type
- Add data points manually or upload a CSV
- Adjust settings as needed
If creating fields manually in ACF, you'll need:
- Chart Type (Select)
- Data Input Method (Radio Button)
- Data Points (Repeater for manual entry)
- CSV Upload (File field)
- Chart Settings (Group with title, legend, and animation options)
For exact field configuration, check the ACF export in field-export.json
Label,Value
January,100
February,150
March,120
- Edit
dynamic-chart.php
to modify the block's HTML structure - Update
chart-logic.js
to change chart behavior - Modify
dynamic-chart.css
to adjust styles
- Built with Advanced Custom Fields PRO
- Charts powered by Chart.js