PHP Charts & Graphs https://phpchart.com Making charts in PHP is simple again. Wed, 19 Jul 2023 03:18:27 +0000 en-US hourly 1 https://wordpress.org/?v=5.8.13 Complete Examples with Source https://phpchart.com/examples/complete-phpchart-examples/ https://phpchart.com/examples/complete-phpchart-examples/#respond Mon, 23 Jun 2014 17:57:37 +0000 http://phpchart.net/?p=358 Below is comprehensive list of all the phpChart examples for your reference. It’s recommended to look at each example as companion exercise to the online documentation to better understand how properties are used in phpChart. Click on text “PHP Source” to reveal the PHP source code. Each example also shows generated javascript and plugins used. […]

The post Complete Examples with Source appeared first on PHP Charts & Graphs.

]]>
Below is comprehensive list of all the phpChart examples for your reference. It’s recommended to look at each example as companion exercise to the online documentation to better understand how properties are used in phpChart.

Click on text “PHP Source” to reveal the PHP source code. Each example also shows generated javascript and plugins used.

phpChart Area Graph
Axis Labels Rotated Text
Axis Labels Rotated Text 2
Axis Labels
Banded Line
Bar, Line, Pie Stacked Graph
Bar with Missing Values
Bar Chart
Bar Chart 2
Basic phpChart
Basic phpChart 2 (AJAX)
Bezier Curve
Block Plot Chart
Break on Null Value
Bubble Chart
Bubble Chart 2
Candle Stick
Canvas Overlay
Run-time Error Catch
Category with Horizontal Bar
Category vs Linear Axes
Chartin Table
ci Parser
Custom Highlighter & Cursor with Trend Line
Pie Chart
Dashed Lines
Data Labels
Data Renderer
Data Tracking
Donut Graph
Donut Graph 2
Dynamic Plotting
Image Export
Filled Line
Filled Line Category Axis
Fill to Zero
Funnel Chart
Grid Customization
Grid Padding
Hidden Plot
Highlighter
Highlighter 2
Highlighter 3
Initial Ticks
Legend Lables
Legend Lables 2
Line, Pie, Bar Mixed PHP Chart
Marker Styles Customization
Mekko Chart
Meter Gauge Chart
Meter Gauge Chart 2
Min & Max Lines
Chart with Missing Values
Multiple Colored Bar Chart
Multiple Lines with Pattern
Multiple Y Axes
Multiple Axes with Rotated Text
No Data
Pie Chart
Pie Chart 2
Pie Chart 3
Pie Chart 4
Point Labels
Point Labels 2
Label with Prefix
Real Time Replotting
Rotated Tick Labels
Rotated Tick Labels with Zoom
Series Canvas Reorder
Series Update
Shadow
Waterfall
Zoom in/out
Data Series With Arbitrary Text and Value Pair
Dots Chart with Trend Line
Curved Line
Display Logarithmic Axis
Dots and Line Chart

Download phpChart

The post Complete Examples with Source appeared first on PHP Charts & Graphs.

]]>
https://phpchart.com/examples/complete-phpchart-examples/feed/ 0
Be Responsive! https://phpchart.com/examples/be-responsive/ https://phpchart.com/examples/be-responsive/#respond Mon, 23 Jun 2014 17:57:26 +0000 http://phpchart.org/?p=1124 With a little tricks with Javascript and CSS, the phpChart can be responsive. It stretches and shrinks based on the page width, perfect for mobile devices such as iOS and Android. The following code snippet works on any charts. Simply copy and paste them to the END of your page before </body> tag. CSS: 123456.jqplot-target{ […]

The post Be Responsive! appeared first on PHP Charts & Graphs.

]]>
With a little tricks with Javascript and CSS, the phpChart can be responsive. It stretches and shrinks based on the page width, perfect for mobile devices such as iOS and Android.

The following code snippet works on any charts. Simply copy and paste them to the END of your page before </body> tag.

CSS:

1
2
3
4
5
6
.jqplot-target{
    position: relative !important;
    width: auto !important;
    /* max-width: 1000px; */ /* OPTIONAL */
    min-width: 300px; /* OPTIONAL */
}

Javascript:

Please note that canvas object name is the chart id with underscore prefix. For instance, if id is “chart1”, then the javascript name is “_chart1”.

1
2
3
4
5
6
7
<script>// <![CDATA[
$(document).ready(function(){
    $(window).resize(function() {
        _chart1.replot( { resetAxes: true } );
    });
});
// ]]></script>

Live demo – Try resize the window using mouse!

The post Be Responsive! appeared first on PHP Charts & Graphs.

]]>
https://phpchart.com/examples/be-responsive/feed/ 0
Logarithmic Axis using LogAxisRenderer https://phpchart.com/examples/logarithmic-axis-using-logaxisrenderer/ https://phpchart.com/examples/logarithmic-axis-using-logaxisrenderer/#respond Mon, 23 Jun 2014 17:56:16 +0000 http://phpchart.org/?p=1115 Display logarithmic axis using LogAxisRenderer. Make sure the tickDistribution is set to “power” for power of 10 display on its axis. 12345678910111213141516171819202122232425<?php $line1 = array(array(100,121), array(2000,21), array(5000,35), array(6600,43)); $pc = new C_PhpChartX(array($line1),'chart_1'); $pc->add_plugins(array('canvasTextRenderer')); // curved line $pc->set_series_default(array('rendererOptions'=> array('smooth'=>true))); // Logarithm $pc->set_axes(array(     'xaxis'  => array(         'renderer'=>'plugin::LogAxisRenderer',         […]

The post Logarithmic Axis using LogAxisRenderer appeared first on PHP Charts & Graphs.

]]>
logarithm_chart

Display logarithmic axis using LogAxisRenderer. Make sure the tickDistribution is set to “power” for power of 10 display on its axis.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
$line1 = array(array(100,121), array(2000,21), array(5000,35), array(6600,43));
$pc = new C_PhpChartX(array($line1),'chart_1');
$pc->add_plugins(array('canvasTextRenderer'));
// curved line
$pc->set_series_default(array('rendererOptions'=> array('smooth'=>true)));
// Logarithm
$pc->set_axes(array(
    'xaxis'  => array(
        'renderer'=>'plugin::LogAxisRenderer',
        'tickOptions'=>array('tickDistribution' =>"power",  // power of 10
                             'formatString'     => "%'i",
                             'showGridline'=>false),
        'labelRenderer'=>'plugin::CanvasAxisLabelRenderer',
        'min'=>0,
        'showGridline'=>false,
        'ticks'=> array(1, 10, 100, 1000, 10000)
        ),

    'yaxis'  => array(
        'autoscale'=>false,
        'tickOptions'=>array('showGridline'=>false),
        'labelRenderer'=>'plugin::CanvasAxisLabelRenderer')
));
$pc->draw(800,500);

Live demo

The post Logarithmic Axis using LogAxisRenderer appeared first on PHP Charts & Graphs.

]]>
https://phpchart.com/examples/logarithmic-axis-using-logaxisrenderer/feed/ 0
Curved Line https://phpchart.com/examples/curved-line/ https://phpchart.com/examples/curved-line/#respond Mon, 23 Jun 2014 05:25:39 +0000 http://phpchart.org/?p=1112 Curved line can be easily achieved with rendererOptions “smooth” property. When it is set to true, it will display a smooth curved line between each points instead of straight lines. 123$pc = new C_PhpChartX(array(array(11, 9, 5, 12, 14)),'basic_chart'); $pc->set_series_default(array('rendererOptions'=> array('smooth'=>true))); $pc->draw(); Live demo!

The post Curved Line appeared first on PHP Charts & Graphs.

]]>
curved-line

Curved line can be easily achieved with rendererOptions “smooth” property. When it is set to true, it will display a smooth curved line between each points instead of straight lines.

1
2
3
$pc = new C_PhpChartX(array(array(11, 9, 5, 12, 14)),'basic_chart');
$pc->set_series_default(array('rendererOptions'=> array('smooth'=>true)));
$pc->draw();

Live demo!

The post Curved Line appeared first on PHP Charts & Graphs.

]]>
https://phpchart.com/examples/curved-line/feed/ 0
Dots Only Chart with Trend Line https://phpchart.com/examples/dots-only-chart/ https://phpchart.com/examples/dots-only-chart/#respond Fri, 20 Jun 2014 18:10:16 +0000 http://phpchart.org/?p=1107 You can also render chart with dots or points only without line in between by setting “showGridLine” to false. You can further remove the grid and borders using set_grid() method. Add plugin “trendline” to show the linear approximation. 12345678910111213$pc = new C_PhpChartX(array(array(11, 9, 5, 12, 14)),'basic_chart'); $pc->add_plugins(array('trendline')); $pc->set_defaults(array('seriesDefaults'=>array('showLine'=>false))); // remove background, border and grid. $pc->set_axes(array( […]

The post Dots Only Chart with Trend Line appeared first on PHP Charts & Graphs.

]]>
phpCharr dot chart

You can also render chart with dots or points only without line in between by setting “showGridLine” to false. You can further remove the grid and borders using set_grid() method. Add plugin “trendline” to show the linear approximation.

1
2
3
4
5
6
7
8
9
10
11
12
13
$pc = new C_PhpChartX(array(array(11, 9, 5, 12, 14)),'basic_chart');
$pc->add_plugins(array('trendline'));
$pc->set_defaults(array('seriesDefaults'=>array('showLine'=>false)));
// remove background, border and grid.
$pc->set_axes(array(
    'xaxis'=>array('tickOptions'=>array('showGridline'=>false)),
    'yaxis'=>array('tickOptions'=>array('showGridline'=>false))));
$pc->set_grid(array(
    'background'=>'white',
    'borderWidth'=>0,
    'borderColor'=>'#000000',
    'shadow'=>false));
$pc->draw();

Live demo

The post Dots Only Chart with Trend Line appeared first on PHP Charts & Graphs.

]]>
https://phpchart.com/examples/dots-only-chart/feed/ 0
Data Series With Arbitrary Values https://phpchart.com/examples/display-data-series-with-arbitrary-text-and-value-pair/ https://phpchart.com/examples/display-data-series-with-arbitrary-text-and-value-pair/#respond Thu, 31 Oct 2013 20:25:20 +0000 http://phpchart.net/?p=979 It’s common to have series that pairs data value with arbitrary text. The key is pair both data value and text in array in the following format and include three plugins: canvasTextRenderer, CategoryAxisRenderer, and CategoryAxisRenderer. 1array(array("text 1", 3), array("another text", 4)...) Complete example: 123456789101112131415161718192021222324252627$line = array(array('Cup Holder Pinion Bob', 7), array('Generic Fog Lamp', 9), array('HDTV […]

The post Data Series With Arbitrary Values appeared first on PHP Charts & Graphs.

]]>
It’s common to have series that pairs data value with arbitrary text. The key is pair both data value and text in array in the following format and include three plugins: canvasTextRenderer, CategoryAxisRenderer, and CategoryAxisRenderer.

1
array(array("text 1", 3), array("another text", 4)...)

Complete example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$line = array(array('Cup Holder Pinion Bob', 7), array('Generic Fog Lamp', 9), array('HDTV Receiver', 15), array('8 Track Control Module', 12), array(' Sludge Pump Fourier Modulator', 3),array('Transcender/Spice Rack', 6), array('Hair Spray Danger Indicator', 18));
$pc = new C_PhpChartX(array($line),'chart_1');
$pc->add_plugins(array('canvasTextRenderer'));

//set animation
$pc->set_animate(true);
//set title
$pc->set_title(array('text'=>'Concern vs. Occurrance'));

//set series
$pc->add_series(array('renderer'=>'plugin::BarRenderer'));
//set axes
$pc->set_axes(array(
        'xaxis'  => array(
            'renderer'=>'plugin::CategoryAxisRenderer',
            'label'=>'Warranty Concern',
            'tickOptions'=>array(
                'enableFontSupport'=>true,'angle'=>-30),
            'tickRenderer'=>'plugin::CanvasAxisTickRenderer'),
        'yaxis'  => array(
            'autoscale'=>true,
            'label'=>'Occurance',
            'tickOptions'=>array('enableFontSupport'=>true,'angle'=>-30),
            'tickRenderer'=>'plugin::CanvasAxisTickRenderer')
     ));

$pc->draw(800,500);

Live demo

The post Data Series With Arbitrary Values appeared first on PHP Charts & Graphs.

]]>
https://phpchart.com/examples/display-data-series-with-arbitrary-text-and-value-pair/feed/ 0
External Data Source through AJAX https://phpchart.com/examples/external-data-source-through-ajax/ https://phpchart.com/examples/external-data-source-through-ajax/#respond Wed, 09 May 2012 05:42:27 +0000 http://phpchart.net/?p=658 Call set_data_renderer() function, and pass the following javascript function as js::ajaxDataRenderer. Note the js:: prefix indicating an external javascript function. Javascript 123456789101112131415var ajaxDataRenderer =     function(url, plot)     {         var ret = null;         $.ajax({             // have to use synchronous […]

The post External Data Source through AJAX appeared first on PHP Charts & Graphs.

]]>
Call set_data_renderer() function, and pass the following javascript function as js::ajaxDataRenderer. Note the js:: prefix indicating an external javascript function.

Javascript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var ajaxDataRenderer =
    function(url, plot)
    {
        var ret = null;
        $.ajax({
            // have to use synchronous here, else returns before data is fetched
            async: false,
            url: url,
            dataType:'json',
            success: function(data) {
                ret = data;
            }
        });
        return ret;
    };

In phpChart constructor, pass the external data source as the first parameter as either a file or URL. In this example, it points to jsondata.txt which is external text file on the same server. But it also can be a URL to an external site.

PHP

1
2
3
4
5
$data1 = array();
$pc = new C_PhpChartX('./jsondata.txt','basic_chart_ajax');
$pc->set_title(array('text'=>'Basic Chart Ajax'));
$pc->set_data_renderer("js::ajaxDataRenderer");
$pc->draw();

jsondata.txt

1
[[1, 3, 2, 4, 6, 9]]

Live demo

The post External Data Source through AJAX appeared first on PHP Charts & Graphs.

]]>
https://phpchart.com/examples/external-data-source-through-ajax/feed/ 0
OHLC, HLC, Candlestick/Stock Charts https://phpchart.com/examples/ohlc-hlc-and-candlestickstock-charts/ https://phpchart.com/examples/ohlc-hlc-and-candlestickstock-charts/#respond Wed, 09 May 2012 04:51:35 +0000 http://phpchart.net/?p=651 OHLC, HLC and Candlestick charts all requires plugin::OHLCRenderer renderer plugin, then simply set the candleStick property to true in rendererOptions. 123$pc->add_series(array(         'renderer'=>'plugin::OHLCRenderer',         'rendererOptions'=>array('candleStick'=>true))); Live demo

The post OHLC, HLC, Candlestick/Stock Charts appeared first on PHP Charts & Graphs.

]]>
OHLC, HLC and Candlestick charts all requires plugin::OHLCRenderer renderer plugin, then simply set the candleStick property to true in rendererOptions.

1
2
3
$pc->add_series(array(
        'renderer'=>'plugin::OHLCRenderer',
        'rendererOptions'=>array('candleStick'=>true)));

Live demo

The post OHLC, HLC, Candlestick/Stock Charts appeared first on PHP Charts & Graphs.

]]>
https://phpchart.com/examples/ohlc-hlc-and-candlestickstock-charts/feed/ 0
Bubble Chart https://phpchart.com/examples/bubble-chart-2/ https://phpchart.com/examples/bubble-chart-2/#respond Tue, 08 May 2012 04:43:07 +0000 http://phpchart.net/?p=646 Bubble chart is a little different from pie and bar charts because it represents three dimensional data. Data is passed in to a bubble chart as a series of [x, y, radius, ]. The optional fourth element of the data point can either be either a label string or an object having ‘label’ and/or ‘color’ […]

The post Bubble Chart appeared first on PHP Charts & Graphs.

]]>
Bubble chart is a little different from pie and bar charts because it represents three dimensional data. Data is passed in to a bubble chart as a series of [x, y, radius, https://phpchart.com/examples/bubble-chart-2/feed/ 0
PHP Pie Chart, Line Chart & Bar Chart https://phpchart.com/examples/line-bar-pie-charts/ https://phpchart.com/examples/line-bar-pie-charts/#respond Tue, 08 May 2012 03:44:52 +0000 http://phpchart.net/?p=635 Line, bar and pie charts are the most commonly used charts. By default, all charts plotted are line charts when no renderer plugin is specified. For bar charts, simply use plugin::BarRenderer, 1$pc->set_series_default(array('renderer'=> 'plugin::BarRenderer', 'rendererOptions'=> array('barPadding'=>6,'barMargin'=>40))); For pie charts, use plugin::PieRenderer when specify renderer property. 1$pc->set_series_default(array('renderer'=> 'plugin::PieRenderer', 'rendererOptions'=> array('sliceMargin'=>8))); List of renderer plugins List of non-renderers […]

The post PHP Pie Chart, Line Chart & Bar Chart appeared first on PHP Charts & Graphs.

]]>
Line, bar and pie charts are the most commonly used charts. By default, all charts plotted are line charts when no renderer plugin is specified.

For bar charts, simply use plugin::BarRenderer,

1
$pc->set_series_default(array('renderer'=> 'plugin::BarRenderer', 'rendererOptions'=> array('barPadding'=>6,'barMargin'=>40)));

For pie charts, use plugin::PieRenderer when specify renderer property.

1
$pc->set_series_default(array('renderer'=> 'plugin::PieRenderer', 'rendererOptions'=> array('sliceMargin'=>8)));

Live demo

The post PHP Pie Chart, Line Chart & Bar Chart appeared first on PHP Charts & Graphs.

]]>
https://phpchart.com/examples/line-bar-pie-charts/feed/ 0