Topnew SVG Chart is responsive to the width of parent box which is calling. eg. Width of parent HTML element box is 500px, SVG Chart will scale to 500px in width.
Topnew SVG Chart is default to 480px width * 250px height. If parent box width is bigger, SVG Chart will look smaller after zoom, and vice versa. The height of a pie chart is automatically calculated, it will ignore the height parameter.
$init['w'] = 'fix'; also accepted to automatically calculate the with of a chart
$data = [2012 => 100,200,300,400,480];
$init['w'] = 900;
echo Chart::svg($data, $init);
$data = [2012 => 100,200,300,400,480];
$init['w'] = 300;
$init['h'] = 100;
You can edit the margins of each side: gapT, gapR, gapB, gapL means margin top, right, bottom and left. A positive number will increase the gap, a negative number will reduce the gap.
$data = [2012 => 100,200,300,400,480];
$init['gapT'] = 20; // add 20px at top
$init['gapR'] = 20;
$init['gapB'] = 20;
$init['gapL'] = -20; // reduce 20px at left
2.3 - title, xTitle, yTitle and align of titles
$data = [2012 => 100,200,300,400,480];
$init['title'] = 'Title of the Chart';
$init['xTitle'] = 'Title for xAxis';
$init['yTitle'] = 'Title for yAxis';
$init['titleAlign'] = 2; // center default
$init['xTitleAlign'] = 3; // right
$init['yTitleAlign'] = 1; // left if yTitle then bottom
2.4 - legend location and legend width
By default legend will appear on the right side of the chart. There will be no legend if chart contains only one serial.
xSkipMax will get xSkip = floor(xNum / xSkipMax) when you want to dynamically set xSkip
xMin, xMax default to data min and max, unless specified. xMin and xMax will only work when xKey in {year, month, week, day, hour}. They are useful to print xAxis when data is missing.
$data = [2012 => 100,200,300,400,480];
$init['xKey'] = 'year';
$init['xMin'] = 2010;
$init['xMax'] = 2018;
ySum = 1 : sum up yVal while x moves, default 0
$data = [2012 => 100,200,300,400,480];
$init['ySum'] = 1;
xSum = 8 (substr(xAxis,0,8)) or 5,2 or -2 to call php::substr
It is easy to have another txt type, which reads a file into str. But too many types might be confusing. Will be added in the future if really needed.
All above data renders into the same chart as following:
sxy format allows max 3 cols each line, 4+ cols will be ignored.
3.2 - data format: xsy (xAxis, serial, yVal)
You should use the default sxy format, but just in case you need SQL type in xsy format.
xsy format allows max 3 cols each line, 4+ cols will be ignored.
In order not to create confusing, we only demo the SQL type here. Though it is also working for array, string, json types.
$data = 'SELECT team, year, count(*) AS qty FROM sales GROUP BY 1,2';
$init['fmt'] = 'sql_xsy';
Compare this chart with 3.1 sxy, you can see the serial and xAxis is swapped.
3.3 - data format: xss (xAxis, serial, serial, serial, ...)
You should use the default sxy format, but just in case you need SQL type in xss format.
There is no limit of cols in each line of xss format. xss actually means xssssss...
Again we only demo the SQL type here. Though it is also working for array, string, json types.
$data = 'SELECT substr(created,1,7) AS month, count(*) AS Hit, count(distinct ip) AS IP, count(distinct uid) AS UID FROM log WHERE year = 2016 GROUP BY 1';
$init['fmt'] = 'sql_xss';
$init['chart'] = 'line';
$init['yFormat'] = 'format';
$init['xFormat'] = 'Date|M';
3.4 - data format: sxx (serial, xAxis, xAxis, ...)
sxx is a rare format, which can be found in odd SQL or xls files:
This time we are going to demo the str type. Though it is also working for array, SQL, json types.