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

Message ListMessage List     Post MessagePost Message

  Is it possible having tooltips with this example code? Need to map user results to points in chart
Posted by Alexander Guevara on Apr-04-2011 02:50
Attachments:
Hi Guys,

Hope you can help me with this. I have the code below which generates this chart

I would like to have tooltips for each point shown in the chart. Is this possible? If is not
possible the way i am doing this now what would you suggest? legends? numbers for
each point? I know the way image maps are supposed to be created are different than
the rest of the charts, i mean, i do my chart call with this

<img src="showchart.php?xxxxx" name="" id=""/>

Where showchart.php is the code below

<code>
<?php
$dataX0 = $dataY0 = array();
if ( $DB->sql_get_num_rows( $sql ) ){
while ( $data = $DB->sql_fetch($sql_query) ):
# The XY points for the scatter chart
$dataX0[] = $data['X_VALUE'];
$dataY0[] = $data['Y_VALUE'];
endwhile;
}else{
//
}
# Create a XYChart object of size 600 x 300 pixels, with a light blue (ccccff)
# background, a black border, and 1 pixel 3D border effect
$c = new XYChart(600, 480, 0xffffff, 0x333333, 0);/*manuki changed this
ccccff*/

# Add a title box to the chart using 16 pts Arial Bold Italic font, with white
text
# on deep blue background
$textBoxObj = $c->addTitle($client['client_name'], "arialbi.ttf", 16,0xffffff);
$textBoxObj->setBackground(0xff6633);/* manuki changed this was
000080*/

# Set the plotarea at (20, 60) and of size 560 x 360 pixels, with grey
(808080)
# border, and light grey (c0c0c0) horizontal and vertical grid lines. Set 4
quadrant
# coloring, where the colors of the quadrants alternate between lighter and
deeper
# grey (dddddd/eeeeee)
$plotAreaObj = $c->setPlotArea(20, 60, 560, 360, -1, -1, 0xc0c0c0, 0xffffff,
0xffffff);
$plotAreaObj->set4QBgColor(0xffffff, 0xffffff, 0xffffff, 0xffffff);/* manuki
changed this was ffffff y dddddd*/

# Set 4 quadrant mode, with both x and y axes symetrical around the origin
$c->setAxisAtOrigin(XYAxisAtOrigin, XAxisSymmetric + YAxisSymmetric);

# Add a legend box at (300, 460) (bottom center of the chart) with
horizontal layout.
# Use 8 pts Arial Bold font.
$legendBox = $c->addLegend(300, 4, false, "arialbd.ttf", 8);//was 460
instead of 4
$legendBox->setAlignment(BottomCenter);

# Set legend box background to light grey (dddddd) with a black border
$legendBox->setBackground(0xffffff, 0);

# Set left/right margin to 20 pixels and top/bottom margin to 5 pixels
$legendBox->setMargin2(20, 20, 5, 5);

# Add a titles to axes
$c->xAxis->setTitle("");
$c->yAxis->setTitle("");

# Set axes width to 2 pixels
$c->xAxis->setWidth(1);
$c->yAxis->setWidth(1);

# Add scatter layer, using 15 pixels red (ff33333) X shape symbols
$c->addScatterLayer($dataX0, $dataY0, "Series 1", CircleShape, 8,
0xff6633);/*manuki changed this ff3333*/

# Add scatter layer, using 15 pixels green (33ff33) 6-sided polygon symbols
#$c->addScatterLayer($dataX1, $dataY1, "Group B", PolygonShape(6), 15,
0x33ff33);

# Add scatter layer, using 15 pixels blue (3333ff) triangle symbols
#$c->addScatterLayer($dataX2, $dataY2, "Group C", TriangleSymbol, 15,
0x3333ff);

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

Hope you can help me, thanks in advance.

Alex
index.php.png

  Re: Is it possible having tooltips with this example code? Need to map user results to points in chart
Posted by Peter Kwan on Apr-04-2011 13:56
Hi Alexander,

There are a number of sample code included in ChartDirector that has tooltips. You may use them as references. They are explained in the "Clickable Charts" section of the ChartDirector documentation.

In brief, you need to put all your charting code in the same file as the <img> tag, and use an alternative output method. It is like:


<?php

$dataX0 = $dataY0 = array();

......... your existing code ............

$c->addScatterLayer($dataX0, $dataY0, "Series 1", CircleShape, 8,
0xff6633); /*manuki changed this ff3333*/

# Create the image and save it in a temporary location
$chart1URL = $c->makeSession("chart1");

# Create an image map for the chart
$imageMap = $c->getHTMLImageMap("", "", "title='({x}, {value})'");
?>
<img src="getchart.php?<?php echo $chart1URL?>" border="0" usemap="#map1">
<map name="map1">
<?php echo $imageMap?>
</map>


Please also copy the file "getchart.php" (included in ChartDirector/phpdemo) to the same directory as your code, as the <img> tag relies on this utility PHP to load the chart image.

Hope this can help.

Regards
Peter Kwan

  Re: Is it possible having tooltips with this example code? Need to map user results to points in chart
Posted by Alexander Guevara on Apr-11-2011 02:10
Hi Peter!!
Sorry for the delay in my response.

Everything is work fine now.. thanks for your help.

However i am missing something i would like to do and can't find the way to do it.

Based on my code above, right now for ht tool tips i am having the X and Y values when i
mouse over the points in my chart. However, i would like to have a different value there
instead of the numbers.

Let's say i want the name of the person that is located over that point given that data. So
instead of having -7,16 i want to show "Alexander" and that's for each dot in the plot.

Is this possible?

Thanks in advance!

  Re: Is it possible having tooltips with this example code? Need to map user results to points in chart
Posted by Peter Kwan on Apr-12-2011 00:22
Hi Alexander,

You can associate an extra field with the data points, and display that field in the tooltip by using {field0} in the tooltip template. The code is like:


$layer = $c->addScatterLayer($dataX0, $dataY0, "Series 1", CircleShape, 8,
0xff6633); /*manuki changed this ff3333*/

//an array of text strings, with one text string for each data point
$layer->addExtraField($anArrayOfNames);

.......


//use {field0} to represent the item from the extra field
$imageMap = $c->getHTMLImageMap("", "", "title='{field0}'");

Hope this can help.

Regards
Peter Kwan

  Re: Is it possible having tooltips with this example code? Need to map user results to points in chart
Posted by Alexander on Apr-12-2011 01:41
Hi Peter!

Thanks so much, already figured it out.. at the beginning i thought it was only for Pie charts...

Thank you so much for your help! now is working like a charm!

Alex