I need to draw a line chart using PHP which fullfills the following requirements:
Textual X-Axis descriptors
Not every serie has values for all X-Axis values
Markers on the given points
I have already detailed watched pChart, JpGraph and LibChart, but I didn't manage to get the expected result. It should look like this (poorly drawn with MsPaint):
EDIT: The exact problems:
With Libchart, I didn't manage to get different series with not all x axis values filled
With pChart, there was the same problem (e.g. at the above example, pChart would not make a line at the blue series from desc 3 to desc 6, when values 4 and 5 have the value VOID). I could also calculate the values between, but then they would also have markers (e.g. at desc 4 and desc 5)
With JpGraph, I didn't manage to create textual x axis values
Thank you for your help, Community!
Found a solution using pChart:
I can use VOID for points which do not have an own value, and set a config setting like the following one:
$myPicture->drawLineChart(array('BreakVoid'=>false,'VoidTicks'=>0));
Using this settings, VOID will draw correct lines to the next known value.
Related
With my previous posts
1. PHPSpreadsheet generates an error "Wrong number of arguments for INDEX() function: 5 given, between 1 and 4 expected"
2. Excel - Getting the Top 5 data of a column and their matching title but produces duplicates
I have found out that the PHPSpreadsheet library for PHP is yet to allow the usage of the AGGREGATE() and complicated formulas/functions but I'm in dire need of their functionalities
Going back, I have 2 columns in my Excel (produced by my web applications made from CodeIgniter and Laravel)
The problem is, the Article Count column (on the right) contains 2 values of 54 which is supposed to belong to 2 different Publications (on the left) but with the use of the formula =INDEX(E$4:E$38,MATCH(M4,J$4:J$38,0)) it just fetches the 1st matched Publication.
The output should look like this:
The original Table:
My question is, what would be the right function or code in Excel so I could retrieve the SECOND Publication of my matched data?
I'm aiming to target those Publications that has the Article Count of 54, but I want to aim the SECOND ONE which is the letter D WITHOUT using the Aggregate() function of Excel
Here are my used codes
1) =LARGE(J4:J38,1) - J4:J38 is my range of raw data, I am using this to get the 5 highest numbers in descending order
2) =INDEX(E4:E38,MATCH(M4,J4:J38,0)) - I'm using this to retrieve the Publication Names that matched the Article Count
After communicating in chat, we got this correct formula:
=INDEX(E$2:E$38,IF(M4=M3,MATCH(L3,E$2:E$38,0),0)+MATCH(M4,OFFSET(J$2,IF(M4=M3,MATCH(L3,E$2:E$38,0),0),0,COUNT(J$2:J$38)-IF(M4=M3,MATCH(L3,E$2:E$38,0),0),1),0))
How this works:
This IF(M4=M3,MATCH(L3,E$2:E$38,0),0) returns the position of the previous row's publication title in the titles array (E), in case the current publication count is the same with the previous one. Let's call this number X. Instead of using J2:J38 for the results, we use J(2+X):J38. This trick is done by using offset to cut off the previous section, already used by the previous row. This way, on repeating publication counts the already mentioned titles get ignored.
You need to use AGGREGATE's SMALL sub-function to return the smallest matching row number and adjust the k argument to accommodate duplicate rankings.
'in M4
=LARGE(J$4:J$38, ROW(1:1))
'in L4
=INDEX(I:I, AGGREGATE(15, 7, ROW($4:$38)/(J$4:J$38=M4), COUNTIF(M$4:M4, M4)))
enter image description here
I have a graph for which I was able to manually create x axis values in a docx template. The template outputs the correct graph. Instead of relying upon manually entering all x values and substituting the values from the php array, I want to dynamically populate the horizontal axis with values from a php array.
PHP Code
// --------------------------------------------
// Merging and other operations on the template
// --------------------------------------------
// Change chart series
$ChartNameOrNum = 'Buildup'; // Title of the shape that embeds the chart
$SeriesNameOrNum = 'Series 1';
$NewValues = array($buildupLabels['TotalActionItems'], $buildupSeries['TotalActionItems'] );
$NewLegend = "Total Action Items";
$TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);
// Delete comments
$TBS->PlugIn(OPENTBS_DELETE_COMMENTS);
Output File with Rendered Chart
Chart Template
Table of x-axis values
How can I achieve the above? Is this possible using the OpenTBS, or do I need to manually enter all x axis values?
OpenTBS enables you to change x and y values for any of the series.
So you just have to change all (x,y) items for all of your series then old x values should totally disappear in your chart. You have to get an automatic min and max for the x axis in order to have it adapted to the new values.
You also have to keep in mind the Ms Office Charts behavior :
If your chart type is a XY (also named Scatter), then (x,y) of your series entries can be in any order, and the x axis will not necessary display values used by items. This is nice when you have several series with different x values and you want to display unused x values in the x axe.
If your chart type different from a XY then x values are considered as categories. Only used values will be displayed in the x axis. If tow series have different categories all possible values are displayed in the x axis.
I just discovered that I do not need to automatically generate all of the horizontal values in the embedded chart. All I need to do is put one date in the first record (e.g. Mar 05 15 or anything else not even in the range of dates I am populating) and the series will automatically populate all available dates from my PHP array.
I'm using the Grid component in fusion charts and need a date string to be used in the value place. It will always fail when i do this as it is looking for a number. Is there anyway it can allow text to be used aswell?
Thanks
The ability to have date-time axis values is not yet available in FusionCharts. Nevertheless, the use case for you does not fit right.
Ideally, the grid component's right column should show a number (value). The left column is text showing the labels. For a grid, it makes very less sense to have text on both columns.
Instead of a date, the right column should show how many month's or days or hours, etc.
Excerpts from FusionCharts documentation: http://docs.fusioncharts.com/charts/contents/advanced/number-format/Number_Scaling.html
Say we're plotting a chart which indicates the time taken by a list of automated processes. Each process in the list can take time ranging from a few seconds to few days. And we've the data for each process in seconds itself. Now, if we were to show all the data on the chart in seconds only, it won't appear too legible. What we can do is build a scale indicating time and then specify it to the chart. This scale, in human terms, would look something as under:
60 seconds = 1 minute
60 minute = 1 hr
24 hrs = 1 day
7 days = 1 week
Now, to convert this scale into FusionCharts XML format, you'll have to do it as under:
First you would need to define the unit of the data which you're providing. Like, in this example, you're providing all data in seconds. So, default number scale would be represented in seconds. We can represent it as <chart defaultNumberScale='s' ...>
Next, we define our own scale for the chart as: <chart numberScaleValue='60,60,24,7' numberScaleUnit='min,hr,day,wk' >. If you carefully see this and match it with our range, you'll find that whatever numeric figures are present on the left hand side of the range is put in numberScaleValue and whatever units are present on the right side of the scale has been put under numberScaleUnit - all separated by commas.
Set the chart formatting flags to on as: <chart formatNumber='1' formatNumberScale='1' ...>
The entire XML would look like:
<chart defaultNumberScale='s' numberScaleValue='60,60,24,7' numberScaleUnit='min,hr,day,wk'><set label='A' value='38' /><set label='B' value='150' /><set label='C' value='11050' /><set label='D' value='334345' /><set label='E' value='1334345' /></chart>
A sample grid (not with the above data) would look like this:
I am trying to make a bargraph that plots times.
So what the technical issue we are trying to get the minimum plot value to something.
For example if what I was trying to graph was 4 min 30 s (4:30), 4:45, 4:15, and 4:20,
I would like the y=0 value to be 4 minutes and each increment in the y axis to be 1 second.
Effectively, it would be a bargraph of 30, 45, 15, and 20 with the y = 0 axis labelled as.
Is there anyway of doing this without have to man handle the data?
Help please if you know how to do this with jpgrah.
Otherwise, does anyone know what this feature is called in general so I can google it up?
I was reading the documentation of jpgrah:
SetYBase seemed a like a good candidate but all it seemed to do when I played with the parameters was shrink the upper limit y-value [Specify the start plot for bars, (minimum Y-value). By default the base uses the value 0 as base.]
Found the appropriate method in the JPGraph documentation:
$aGraph = new Graph($aWidth,$aHeight,'auto');
$graph->SetScale('textlin',$aMinY,$aMaxY);
$aMinY and $aMaxY give the minimum and maximum values included in the graph.
Also, they are optional arguments.
I have some data of balances ($), dates, and memos. I want to plot this as a line graph. I was happily plotting away with http://www.maani.us/xml_charts/ until I realized that my x-axis was off: there aren't balances for every day, and sometimes there are multiple balances on a single day. How can I compensate for this (space out the dates appropriately)?. I tried using unix_timestamps for the dates so that it could have a numeric value, but this only works for scatter plots (and it sucks at that). The memos I want to appear as tooltips.
Are there any other libraries/APIs that can handle this? Will Fusion Charts do it? Basically I need a chart API that can handle numeric values for both the X and Y axis, but allows me to rename the X axis so it doesn't actually appear as numbers, and supports tooltips (ie is flash based).
Mark,
In FusionCharts scatter chart, we've numeric x and y axis. The good part is that the scatter chart can be made to behave like a line chart. You can connect the points of the scatter chart using a line by setting:
<dataset drawLine='1' ....>
So to show dates on the x-axis, do the following:
Set the value of the least date in your dataset as 0
For every other date, calculate the dateDiff(leastDate, days) and set that as the x-axis value.
Hope that helps...