How to force Y axis to use integers in PHPExcel? - php

This is the graph I get, when I have only numbers below 2. I am generating a report and I'd like to use only integers on Y axis labels. Is there a way to force it in PHPExcel? All the numbers are integers, since they are ratings ranging 1-5. Bars represent the number of ratings.
The options to change are major/minor units in Excel:

Related

Adding Percentage Number Format in PHP Excel

When I set format of a cell as %, it automatically multiplies the value with 100 & shows the value. So 94 becomes 9400%.
I want to apply % format on a column but want to keep the values same as before. I just want % sign to be shown along with the value. My Value should be 94% . To achieve this, I used following format code
$this->_xls_current_sheet->getStyle($cell_coordinates)->getNumberFormat()->applyFromArray(
array(
'code' => PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE
));
If you store 0.5 in a cell, and format it as a percentage, then it will appear as 50%.... if you store 50 in a cell, and format it as a percentage, then it will appear as 5000% that is how it should be.
If you enter 50 as a number in the MS Excel GUI, and then set the format mask manually to a percentage, you will get a displayed value of 5000%. However, if you enter 50% in the MS Excel GUI, then MS Excel divides the value by 100 to store 0.5 in the cell, and formats it as a percentage (two actions in one step). If you set 50% in this way in MS Excel, and then change the format mask from percentage to number, then you will see that MS Excel has done this division for you.
PHPExcel doesn't do this (by default)... it expects you to set the correct value and the format as two separate steps. So PHPExcel expects you to store the correct value in the cell (0.5) in the first place, when you want to format it as a percentage.... it will not magically change the value in any way, it doesn't multiply it at all.
Note that if you are using the advanced value binder (rather than the default value binder), and set the cell value to 50%, then PHPExcel will divide by 100 and set to a percentage automatically, in the same way as the MS Excel GUI.

PHPExcel get cell from x and y

I'm making a program and i'm using PHPExcel. Inside the program you can select width and height. (width is the green row, and blue is the height)
All the white numbers are prices.
Lets say i insert 1400 width and 1600 height. the price should be 640. How can i achieve this?
The easiest option is to find which column contains 1400 in Row 1 (D in your example), and which row contains 1600 in column A (5 in your example), and then use that to read the value at that cell (D5)
A somewhat cleverer way is to use an Excel Formula:
=INDIRECT(CONCATENATE(SUBSTITUTE(ADDRESS(1,MATCH(1400,A1:E1,0),4),1,""),MATCH(1600,A1:A17,0)))
substituting the appropriate lookup values for 1400 and 1600, and adjusting the MATCH ranges to the full size for your width and height lookups.... In MS Excel itself, you could use row and column ranges (A:A) and (1:1), but the PHPExcel calculation engine won't handle row and column ranges correctly, but it will work with cell ranges
As an explanation for the above formula:
MATCH(1400,A1:E1,0)
Does a lookup for value 1400 in the cell range A1:E1 (looking for a match for your width). The returned value for MATCH() is a numeric offset in that row for the column where it is found. In this case, it will return 4.
SUBSTITUTE(ADDRESS(1,<4>,4),1,"")
Converts the column number to a column letter... e.g converts 4 to D. if your range didn't start at A, then you'd have to add an offset to get the correct letter
MATCH(1600,A1:A17,0)
Similar to the previous MATCH, but this time searching in your heights column range (A1:A17) for the value 1600. It will return the offset within that range where it finds the value. Again, if your range doesn't start in row 1, then you'd need to add an offset. In your case, it will return 5.
CONCATENATE(<D>,<5>)
Concatenates the calculated column and row values together to give a cell address (D5)
INDIRECT(<D5>)
Reads the value at the cell address that we've calculated (D5) giving the value 640

Jpgraph axis number format: Engineering notation for large numbers

I'm using jpgraph to create some plots from measured data.
Now I have a scatter-plot with large numbers on the y-axis.
I would like to change the number format to a number and exponent instead of just showing an integer. Unfortunately I did not find any solution on-line.
The y-axis has a range of 0 to 12000000. I want to display 12E6 instead of 12000000.
Is this possible? Maybe with the SetFormat?

Change a highchart subtittle

Is it possible to change the X axis labels of a highchart to include a decimal separator?
My X axis has the following values 10000,20000,30000 I need to convert to 10.000,20.000,30.000
Try the format option in the docs
Example appending km to the axis points
Example formatting to 3 decimal places
Thousands separator and one decimal place: {value.y:,.1f}

PHP Flash Charts API w/ Missing Dates?

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...

Categories