Files
Phraseanet/www/include/jslibs/yui2.8/examples/charts/charts-seriescustomization_clean.html
2011-02-16 16:09:48 +01:00

294 lines
7.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Customize series items</title>
<style type="text/css">
/*margin and padding on body element
can introduce errors in determining
element position and are not recommended;
we turn them off as a foundation for YUI
CSS treatments. */
body {
margin:0;
padding:0;
}
</style>
<link rel="stylesheet" type="text/css" href="../../build/fonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="../../build/json/json-min.js"></script>
<script type="text/javascript" src="../../build/element/element-min.js"></script>
<script type="text/javascript" src="../../build/datasource/datasource-min.js"></script>
<script type="text/javascript" src="../../build/swf/swf-min.js"></script>
<script type="text/javascript" src="../../build/charts/charts-min.js"></script>
<!--begin custom header content for this example-->
<style type="text/css">
#chart
{
width: 600px;
height: 350px;
margin-bottom: 10px;
}
.yui-dt-table {width: 500px;}
.chart_title
{
display: block;
font-size: 1.2em;
font-weight: bold;
margin-bottom: 0.4em;
}
</style>
<!--end custom header content for this example-->
</head>
<body class="yui-skin-sam">
<h1>Customize series items</h1>
<div class="exampleIntro">
<p>A <a href="http://developer.yahoo.com/yui/charts/">YUI Charts Control</a> can be configured at the Chart and series level. In this example, we'll use series properties to customize a combination chart.</p>
<p>Please note: The YUI Charts Control requires Flash Player 9.0.45 or higher. The latest version of Flash Player is available at the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.</p>
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->
<span class="chart_title">Personal Finances</span>
<div id="chart">Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can download the latest version of Flash Player from the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.</p></div>
<script type="text/javascript">
YAHOO.widget.Chart.SWFURL = "../../build/charts/assets/charts.swf";
//--- data
YAHOO.example.monthlyExpenses =
[
{
month: "January",
rent: -1280.00,
utilities: -494.68,
gamblingprofits:292.00,
gamblinglosses:-85.00,
pay:2450.00,
incidentals:-654.32
},
{
month: "February",
rent: -1280.00,
utilities: -401.35,
gamblingprofits:292.00,
gamblinglosses:-185.00,
pay:2450.00,
incidentals:-432.26
},
{
month: "March",
rent: -1280.00,
utilities: -489.32,
gamblingprofits:292.00,
gamblinglosses:-485.00,
pay:2450.00,
incidentals:-523.33
},
{
month: "April",
rent: -1280.00,
utilities: -484.71,
gamblingprofits:292.00,
gamblinglosses:-185.00,
pay:2450.00,
incidentals:-765.45
},
{
month: "May",
rent: -1310.00,
utilities: -479.811,
gamblingprofits:292.00,
gamblinglosses:-485.00,
pay:2450.00,
incidentals:-555.11
},
{
month: "June",
rent: -1310.00,
utilities: -497.95,
gamblingprofits:292.00,
gamblinglosses:-220.00,
pay:2450.00,
incidentals:-633.48
}
];
function calculateNet(dataArray)
{
var len = dataArray.length;
var obj, net;
for(var i = 0; i < len; i++)
{
obj = dataArray[i];
net = 0;
for(var z in obj)
{
if (!isNaN(obj[z])) net += obj[z];
}
obj.net = net;
}
return dataArray;
}
var myDataSource = new YAHOO.util.DataSource( calculateNet(YAHOO.example.monthlyExpenses) );
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
myDataSource.responseSchema =
{
fields: [ "month", "rent", "utilities", "gamblinglosses", "gamblingprofits", "pay", "incidentals", "net" ]
};
//--- chart
YAHOO.example.formatCurrencyAxisLabel = function( value )
{
return YAHOO.util.Number.format( value,
{
prefix: "$",
thousandsSeparator: ",",
decimalPlaces: 2
});
}
YAHOO.example.getDataTipText = function( item, index, series )
{
var toolTipText = series.displayName + " for " + item.month;
toolTipText += "\n" + YAHOO.example.formatCurrencyAxisLabel( Math.abs(item[series.yField]) );
return toolTipText;
}
YAHOO.example.gainsLossesDataTipFunction = function( item, index, series )
{
var amt = item[series.yField];
var toolTipText = series.displayName + (amt >= 0 ? " Gains" : " Losses") + " for " + item.month;;
toolTipText += "\n" + YAHOO.example.formatCurrencyAxisLabel( Math.abs(amt) );
return toolTipText;
}
YAHOO.example.getLegendLabelText = function(value)
{
return value;
}
YAHOO.example.getGamblingLegendLabelText = function(value)
{
return value + " (wins/losses)";
}
var seriesDef =
[
{
displayName: "Rent",
yField: "rent",
style:{borderColor:0x006600}
},
{
displayName: "Utilities",
yField: "utilities",
style:{borderColor:0x006699}
},
{
displayName: "Gambling",
yField:"gamblingprofits",
style:{borderColor:0x000000, fillColor:0xff0000},
legendLabelFunction:YAHOO.example.getGamblingLegendLabelText,
dataTipFunction:YAHOO.example.gainsLossesDataTipFunction
},
{
displayName: "Gambling",
yField:"gamblinglosses",
style:{borderColor:0x000000, fillColor:0xff0000},
showInLegend:false,
dataTipFunction:YAHOO.example.gainsLossesDataTipFunction
},
{
displayName: "Pay",
yField:"pay",
style:{borderColor:0x000000}
},
{
displayName: "Misc.",
yField:"incidentals",
style:{borderColor:0x660000}
},
{
type:"line",
displayName: "Net",
yField:"net",
style:{fillColor:0xdddeee, borderColor:0x0000ff, lineColor:0x0000ff, skin:"DiamondSkin"},
dataTipFunction:YAHOO.example.gainsLossesDataTipFunction
}
];
var currencyAxis = new YAHOO.widget.NumericAxis();
currencyAxis.labelFunction = YAHOO.example.formatCurrencyAxisLabel;
currencyAxis.title = "Money Gained";
var categoryAxis = new YAHOO.widget.CategoryAxis();
categoryAxis.title = "Month";
var styleDef =
{
font:{color:0xeeeeee},
background:{color:0x677164},
border:{size:1, color:0x000000},
yAxis:
{
titleRotation:90,
color:0xeeeeee,
titleFont:{color:0xeeeeee},
majorGridLines:{color:0xeeeeee},
minorTicks:{display:"none"},
majorTicks:{display:"none"}
},
xAxis:
{
color:0xeeeeee,
titleFont:{color:0xeeeeee}
},
legend:
{
display: "bottom",
padding: 10,
spacing: 5,
font:
{
color:0xeeeeee,
family: "Arial",
size: 11
}
}
}
var mychart = new YAHOO.widget.ColumnChart( "chart", myDataSource,
{
series: seriesDef,
xField: "month",
yAxis: currencyAxis,
xAxis: categoryAxis,
style: styleDef,
legendLabelFunction: YAHOO.example.getLegendLabelText,
dataTipFunction: YAHOO.example.getDataTipText,
//only needed for flash player express install
expressInstall: "assets/expressinstall.swf"
});
</script>
<!--END SOURCE CODE FOR EXAMPLE =============================== -->
</body>
</html>