View Full Version : displaying decimal values
theo373559
01-17-2011, 08:36 AM
I have created two charts using variables for the y axis that are configured in the mysql database as decimal 10,2. (They display as such in the database.) However, as you can see at: http://www.devtestservice.org/coherence/coherence_scale.php
the mean values are whole numbers. This is not good.
I have attached what I think are the relevant documents.
Jason Byrnes
01-17-2011, 12:41 PM
the data passed into the chart will need to use the period decimal separator instead of the comma.
in design view, click the Edit XML. In the XML File, locate the </data> tag. Then add the following after it:
<numformat comma_decimal="true" />
this will display the chart using the comma separator in place of the period
theo373559
01-18-2011, 03:56 AM
I'm afraid my comma was misleading. I was not using it to imply that the variable was coded with a comma, just that it was a decimal with two decimal places.
Here is the data tag code from the xml editor:
<data>
<dataset style="{font-size:9px;color:#767a7f;}" size="9" width="2" color="#173232" label="Scores" dotsize="5" opacity="80" abstraction="4" outline="#568176" linecolor="#568176" type="bar" subtype="fade">
<?php do { ?><point >
<label><?php echo($row_WADWCla_scores['XLABEL']); ?></label>
<value><?php echo($row_WADWCla_scores['YVALUE']); ?></value>
</point><?php } while ($row_WADWCla_scores = mysql_fetch_assoc($WADWCla_scores)); ?>
</dataset>
</data>
There is no statement about the data type that I can see. And it is not clear where it should go.
Jason Byrnes
01-18-2011, 08:39 AM
to force the chart top show 2 decimal places;
edit the </data> tag to:
</data><numformat decimals="2" force="true" />
you can add comma_decimal="true" if you want it to use commas as the decimal separator:
</data><numformat decimals="2" force="true" comma_decimal="true" />
theo373559
01-18-2011, 09:17 AM
I edited the </data> tag to:
</data><numformat decimals="2" force="true" />
and uploaded the includes
but it does not correct my problem. All it does is add decimal points to the Y axis labels.
The graph still shows bars that represent whole numbers. I want the bars themselves to show the actual means.
Jason Byrnes
01-18-2011, 09:23 AM
but all of the data points coming from the database are whole numbers. When i view source of the http://www.devtestservice.org/DynamicWebCharts/Data/coherence_scale_data1.php page, I dont see any values coming from the database that have asn actuall decimal value, they are all .00
<dataset style="{font-size:9px;color:#767a7f;}" size="9" width="2" color="#173232" label="Scores" dotsize="5" opacity="80" abstraction="4" outline="#568176" linecolor="#568176" type="bar" subtype="fade">
<point >
<label>10:4</label>
<value>2.00</value>
</point><point >
<label>11:1</label>
<value>2.00</value>
</point><point >
<label>11:2</label>
<value>2.00</value>
</point><point >
<label>11:2</label>
<value>2.00</value>
</point><point >
<label>11:2</label>
<value>2.00</value>
</point><point >
<label>11:2</label>
<value>2.00</value>
</point><point >
<label>11:2</label>
<value>2.00</value>
</point><point >
<label>11:2</label>
<value>2.00</value>
</point><point >
<label>11:2</label>
<value>2.00</value>
</point><point >
<label>11:2</label>
<value>2.00</value>
</point><point >
<label>11:2</label>
<value>2.00</value>
</point><point >
<label>11:2</label>
<value>3.00</value>
</point><point >
<label>11:3</label>
<value>3.00</value>
</point><point >
<label>11:3</label>
<value>2.00</value>
</point><point >
<label>11:3</label>
<value>2.00</value>
</point><point >
<label>11:3</label>
<value>2.00</value>
</point><point >
<label>11:3</label>
<value>1.00</value>
</point><point >
<label>11:3</label>
<value>2.00</value>
</point><point >
<label>11:3</label>
<value>2.00</value>
</point><point >
<label>11:3</label>
<value>2.00</value>
</point><point >
<label>11:3</label>
<value>2.00</value>
</point><point >
<label>11:3</label>
<value>2.00</value>
</point><point >
<label>11:3</label>
<value>2.00</value>
</point><point >
<label>11:3</label>
<value>3.00</value>
</point><point >
<label>11:4</label>
<value>2.00</value>
</point><point >
<label>11:4</label>
<value>3.00</value>
</point><point >
<label>11:4</label>
<value>2.00</value>
</point><point >
<label>11:4</label>
<value>2.00</value>
</point><point >
<label>11:4</label>
<value>3.00</value>
</point><point >
<label>11:4</label>
<value>2.00</value>
</point><point >
<label>11:4</label>
<value>3.00</value>
</point><point >
<label>11:4</label>
<value>3.00</value>
</point><point >
<label>11:4</label>
<value>3.00</value>
</point><point >
<label>12:1</label>
<value>3.00</value>
</point><point >
<label>12:1</label>
<value>2.00</value>
</point><point >
<label>12:1</label>
<value>3.00</value>
</point><point >
<label>12:1</label>
<value>3.00</value>
</point><point >
<label>12:1</label>
<value>3.00</value>
</point><point >
<label>12:1</label>
<value>2.00</value>
</point><point >
<label>12:1</label>
<value>4.00</value>
</point><point >
<label>12:1</label>
<value>2.00</value>
</point><point >
<label>12:1</label>
<value>3.00</value>
</point><point >
<label>12:2</label>
<value>3.00</value>
</point><point >
<label>12:2</label>
<value>3.00</value>
</point><point >
<label>12:2</label>
<value>4.00</value>
</point><point >
<label>12:2</label>
<value>3.00</value>
</point><point >
<label>12:2</label>
<value>5.00</value>
</point> </dataset>
</data>
</wa_dwc>
theo373559
01-18-2011, 10:41 AM
When average scores across a range of cases are calculated, the result is usually a decimal value. E.g., the average of 2.0 + 3.0 = 2.5. The bars represent average scores, so why do I see bars that are all at levels 1, 2, 3, 4, or 5.
Jason Byrnes
01-18-2011, 11:01 AM
from what I can see, it does not look like the chart is set up to create an average, but I cant really answer that question without more details.
can you send a copy of ythe DynamicWebCharts/Data/coherence_scale_data1.php page, it would also help to have a dump of the database to reproduce the problem on my system to look into it further.
theo373559
01-18-2011, 12:53 PM
That's what I suspected. I'm including the code from coherence_scale_data1.php in the text of this message, and the data table (la_scores.php) as an upload.
<?php require_once('../../Connections/Assessment.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
mysql_select_db($database_Assessment, $Assessment);
$query_WADWCla_scores = "SELECT lasname_1a AS XLABEL, coherence_framing AS YVALUE FROM la_scores ORDER BY lasname_1a ASC";
$WADWCla_scores = mysql_query($query_WADWCla_scores, $Assessment) or die(mysql_error());
$row_WADWCla_scores = mysql_fetch_assoc($WADWCla_scores);
$totalRows_WADWCla_scores = mysql_num_rows($WADWCla_scores);
?>
<?php echo "<" . "?xml version=\"1.0\" encoding=\"utf-8\" ?".">"; ?><!DOCTYPE wa_dwc SYSTEM "wa_dwc.dtd">
<wa_dwc name="DTS" version="1.0">
<color_wheel name="SLATE">
<color>#173232</color>
<color>#7171</color>
<color>#70c7b1</color>
<color>#9696</color>
<color>#faeedb</color>
<color>#e0aa81</color>
</color_wheel>
<title style=" font-size:14px; color:#303431; text-align:center;">FRAMING</title>
<background color="#F4F6F2" align="left" valign="top"/>
<innerbg startcolor="#dcebe2" endcolor="#7cbaaa" direction="90"/>
<yaxis color="#568176" gridcolor="#6da496">
<labels size="11" fontcolor="#3b6e72" linecolor="#6da496">
</labels>
<legend size="12" color="#173232">Framing</legend>
</yaxis>
<xaxis color="#568176" gridcolor="#6da496" offset="true">
<legend size="12" color="#2d2b2e">Phase%20score</legend>
<labels size="11" fontcolor="#3b6e72" orientation="2" linecolor="#6da496">
</labels>
</xaxis>
<data>
<dataset style="{font-size:9px;color:#767a7f;}" size="9" width="2" color="#173232" label="Scores" dotsize="5" opacity="80" abstraction="4" outline="#568176" linecolor="#568176" type="bar" subtype="fade">
<?php do { ?><point >
<label><?php echo($row_WADWCla_scores['XLABEL']); ?></label>
<value><?php echo($row_WADWCla_scores['YVALUE']); ?></value>
</point><?php } while ($row_WADWCla_scores = mysql_fetch_assoc($WADWCla_scores)); ?>
</dataset>
</data>
</wa_dwc>
<?php
mysql_free_result($WADWCla_scores);
?>
Jason Byrnes
01-18-2011, 01:05 PM
the recordset on this page:
SELECT lasname_1a AS XLABEL, coherence_framing AS YVALUE FROM la_scores ORDER BY lasname_1a ASC
is not set to do any averaging.
you need to set this in the chart wizard to average the la_scores columns.
theo373559
01-18-2011, 04:05 PM
I tried several times, always setting the average option. It did not work. At one point I had to reload the extension because it was "remembering" old settings and not allowing me to make new tables with new settings.
Please tell me how to write the code to create an average score. I'd rather not keep fighting with the wizard.
Jason Byrnes
01-19-2011, 08:36 AM
I think this should do the trick
SELECT lasname_1a AS XLABEL, AVG(coherence_framing) AS YVALUE FROM la_scores ORDER BY lasname_1a ASC
theo373559
01-19-2011, 11:20 AM
Go here to see the result:
http://www.devtestservice.org/coherence/coherence_scale.php
????
Jason Byrnes
01-19-2011, 11:28 AM
Sorry, needs a group by clause:
SELECT lasname_1a AS XLABEL, AVG(coherence_framing) AS YVALUE FROM la_scores GROUP BY lasname_1a ORDER BY lasname_1a ASC
theo373559
01-19-2011, 12:26 PM
That's it.
Thanks!
Jason Byrnes
01-19-2011, 01:21 PM
glad to hear it is working.
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.