ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Matrix Chart
Posted by Digitalalpha on Jul-11-2016 06:26
Hi,

I want to create the following chart with a matrix view.

http://www.buyupside.com/winnerslosersmap/wlmapdisplayform.php?stock=MSFT&duration=1&submit=Display

I am using php to create the above. I have a rows array called data which have all the calculated values in both positive and negetive numbers.

row1[] = (10, -2, 40, 60, -23...);
row2[] = (20, 30, 40 , -10..);

1. I want to also adjust the colours with range like;
all positve numbers from >= 0 and <= 20 ( light green)
>20 and <=50 (medum green)
>50 (dark green)

and similarly
<0 and >= -20 (light red)
< -20 and >= -50 (medium red)
< - 50 (dark red)

2. Remember, the total data points can be from 256 to 5000.

Can you help to see how can I plot this using your php library.

Many Thanks for your kind help here...

  Re: Matrix Chart
Posted by Peter Kwan on Jul-12-2016 03:08
Hi Digitalalpha,

I can think of two methods:

(a) Use one scatter layer with rectangle symbols for cells of the same colors. For your case, you have six colors, so you can use six scatter layers.

Basically, you can loop through your data to pick only the points that are >= 0 and <= 20, the create a scatter layer for those points. Then repeat for the other data range.

(b) Use something like a wafer chart. See:

http://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1340610047#N1340657839

Regards
Peter Kwan

  Re: Matrix Chart
Posted by Digitalalpha on Jul-12-2016 08:13
HI Peter,

I like option a).

Can you give a sample php code for me to play around. I want the chart to be same as per my URL given. i.e. It's like half Box (matrix chart)...

Many many thanks Peter!

  Re: Matrix Chart
Posted by Peter Kwan on Jul-13-2016 03:13
Hi Digitalalpha,

Below is an example of a chart with multiple scatter layers, with each layer containing the cells of certain data range. I think you can use this as a reference to create your own code.


<?php
require_once("../lib/phpchartdir.php");

$row0 = array(60, 11, 33, 55);
$row1 = array(30, 30, 4);
$row2 = array(14, 60);
$row3 = array(10);
$allRows = array($row0, $row1, $row2, $row3);

$lowerLimit = array(0, 25, 50);
$upperLimit = array(25, 50, 9999);
$color = array(0xff0000, 0xffcc00, 0x66ccff);

$cellSize = floor(350 / count($row0));
$plotAreaWidth = $cellSize * count($row0);

$c = new XYChart($plotAreaWidth + 100, $plotAreaWidth + 100);
$c->setPlotArea(50, 50, $plotAreaWidth, $plotAreaWidth, -1, -1, 0x444444, Transparent, Transparent);

for ($i = 0; $i < count($lowerLimit); ++$i) {
$min = $lowerLimit[$i];
$max = $upperLimit[$i];
$xCoor = array();
$yCoor = array();
for ($j = 0; $j < count($allRows); ++$j) {
$row = $allRows[$j];
for ($k = 0; $k < count($row); ++$k) {
if (($row[$k] >= $min) && ($row[$k] < $max)) {
$xCoor[] = $k + 0.5;
$yCoor[] = $j + 0.5;
}
}
}
$c->addScatterLayer($xCoor, $yCoor, "", SquareSymbol, $cellSize, $color[$i], $color[$i]);
}

$c->yAxis->setReverse();
$c->xAxis->setLinearScale(0, count($row0), 1);
$c->yAxis->setLinearScale(0, count($row0), 1);

# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>


Regards
Peter Kwan