JavaScript DHTML/YUI Library/Chart

Материал из Web эксперт
Перейти к: навигация, поиск

Chart and DataTable Example

   <source lang="html4strict">


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Chart and DataTable Example</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="yui_2.7.0b-lib/fonts/fonts-min.css" /> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/datatable/assets/skins/sam/datatable.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/json/json-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/datasource/datasource-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/datatable/datatable-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/charts/charts-min.js"></script>


<style type="text/css">

 #chart
 {
   width: 500px;
   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>

</head> <body class=" yui-skin-sam">

Chart and DataTable Example

A <a href="http://developer.yahoo.ru/yui/charts/">YUI Charts Control</a> and a <a href="http://developer.yahoo.ru/yui/datatable/">DataTable Control</a> may share a <a href="http://developer.yahoo.ru/yui/datasource/">DataSource</a> to display the same data.

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.

Widgets, Inc. Financial Summary 2003-2006

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.</p>

<script type="text/javascript">

 YAHOO.widget.Chart.SWFURL = "yui_2.7.0b-lib/charts/assets/charts.swf";
 //used to format x axis labels
 YAHOO.example.numberToCurrency = function( value )
 {
   return YAHOO.util.Number.format(Number(value), {prefix: "$", thousandsSeparator: ","});
 }
 //manipulating the DOM causes problems in ie, so create after window fires "load"
 YAHOO.util.Event.addListener(window, "load", function()
 {
 //--- data
   YAHOO.example.annualIncome =
   [
     { year: 2003, revenue: 1246852, expense: 1123359, income: 123493 },
     { year: 2004, revenue: 2451876, expense: 2084952, income: 366920 },
     { year: 2005, revenue: 2917246, expense: 2587151, income: 330095 },
     { year: 2006, revenue: 3318185, expense: 3087456, income: 230729 }
   ];
   var incomeData = new YAHOO.util.DataSource( YAHOO.example.annualIncome );
   incomeData.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
   incomeData.responseSchema = { fields: [ "year", "revenue", "expense", "income" ] };
 //--- chart
   var seriesDef =
   [
     {
       xField: "revenue",
       displayName: "Revenue"
     },
     {
       xField: "expense",
       displayName: "Expense"
     },
     {
       type: "line",
       xField: "income",
       displayName: "Income"
     }
   ];
   var currencyAxis = new YAHOO.widget.NumericAxis();
   currencyAxis.labelFunction = "YAHOO.example.numberToCurrency";
   var mychart = new YAHOO.widget.BarChart( "chart", incomeData,
   {
     series: seriesDef,
     yField: "year",
     xAxis: currencyAxis,
     //only needed for flash player express install
     expressInstall: "yui_2.7.0b-assets/charts-assets/expressinstall.swf"
   });
 //--- data table
   var columns =
   [
     { key: "year", sortable: true, resizeable: true },
     { key: "revenue", formatter: "currency", sortable: true, resizeable: true },
     { key: "expense", formatter: "currency", sortable: true, resizeable: true },
     { key: "income", formatter: "currency", sortable: true, resizeable: true }
   ];
   var mytable = new YAHOO.widget.DataTable( "datatable", columns, incomeData,
     { sortedBy: { key: "year", dir: "asc" }
   });
 });

</script>

</body>

 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Charts in a TabView

   <source lang="html4strict">


<head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Charts in a TabView</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="yui_2.7.0b-lib/fonts/fonts-min.css" /> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/tabview/assets/skins/sam/tabview.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/json/json-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/datasource/datasource-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/charts/charts-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/tabview/tabview-min.js"></script>


<style type="text/css">

 .chart
 {
   width: 500px;
   height: 350px;
   margin-bottom: 10px;
 }
 .chart_title
 {
   display: block;
   font-size: 1.2em;
   font-weight: bold;
   margin-bottom: 0.4em;
 }
 #tabContainer
 {
   width: 520px;
 }

</style>

</head> <body class=" yui-skin-sam">

Charts in a TabView

This example uses the <a href="http://developer.yahoo.ru/yui/charts/">YUI Charts Control</a> and the <a href="http://developer.yahoo.ru/yui/tabview/">TabView Control</a> to display different views of the same <a href="http://developer.yahoo.ru/yui/datasource/">DataSource</a>.

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.


Monthly Expenses

<script type="text/javascript">

 YAHOO.widget.Chart.SWFURL = "yui_2.7.0b-lib/charts/assets/charts.swf";

//--- DataSource

 YAHOO.example.monthlyExpenses =
 [
   { month: "January", rent: 880.00, utilities: 894.68 },
   { month: "February", rent: 880.00, utilities: 901.35 },
   { month: "March", rent: 880.00, utilities: 889.32 },
   { month: "April", rent: 880.00, utilities: 884.71 },
   { month: "May", rent: 910.00, utilities: 879.811 },
   { month: "June", rent: 910.00, utilities: 897.95 }
 ];
 var myDataSource = new YAHOO.util.DataSource( YAHOO.example.monthlyExpenses );
 myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
 myDataSource.responseSchema =
 {
   fields: [ "month", "rent", "utilities" ]
 };

//--- tabView

 //Create a TabView
 var tabView = new YAHOO.widget.TabView();
 //Add a tab for the Bar Chart
 tabView.addTab( new YAHOO.widget.Tab({
     label: "Bar Chart",
content: "Bar Chart
",
     active: true
 }));
 //Add a tab for the Line Chart
 tabView.addTab( new YAHOO.widget.Tab({
     label: "Line Chart",
content: "Line Chart
"
 }));
 //Add a tab for the Column Chart
 tabView.addTab( new YAHOO.widget.Tab({
     label: "Column Chart",
content: "Column Chart
"
 }));
 //Append TabView to its container div
 tabView.appendTo("tabContainer");

//--- chart

 //series definition for Column and Line Charts
 var seriesDef =
 [
   { displayName: "Rent", yField: "rent" },
   { displayName: "Utilities", yField: "utilities" }
 ];
 //series definition for Bar Chart
 var barChartSeriesDef =
 [
   { displayName: "Rent", xField: "rent" },
   { displayName: "Utilities", xField: "utilities" }
 ];
 //format currency
 YAHOO.example.formatCurrencyAxisLabel = function( value )
 {
   return YAHOO.util.Number.format( value,
   {
     prefix: "$",
     thousandsSeparator: ",",
     decimalPlaces: 2
   });
 }
 //return the formatted text
 YAHOO.example.getDataTipText = function( item, index, series, axisField )
 {
   var toolTipText = series.displayName + " for " + item.month;
   toolTipText += "\n" + YAHOO.example.formatCurrencyAxisLabel( item[series[axisField]] );
   return toolTipText;
 }
 //DataTip function for the Line Chart and Column Chart
 YAHOO.example.getYAxisDataTipText = function( item, index, series )
 {
   return YAHOO.example.getDataTipText(item, index, series, "yField");
 }
 //DataTip function for the Bar Chart
 YAHOO.example.getXAxisDataTipText = function( item, index, series )
 {
   return YAHOO.example.getDataTipText(item, index, series, "xField");
 }
 //create a Numeric Axis for displaying dollars
 var currencyAxis = new YAHOO.widget.NumericAxis();
 currencyAxis.minimum = 800;
 currencyAxis.labelFunction = YAHOO.example.formatCurrencyAxisLabel;
 //Create Line Chart
 var lineChart = new YAHOO.widget.LineChart( "linechart", myDataSource,
 {
   series: seriesDef,
   xField: "month",
   yAxis: currencyAxis,
   dataTipFunction: YAHOO.example.getYAxisDataTipText,
   //only needed for flash player express install
   expressInstall: "yui_2.7.0b-assets/charts-assets/expressinstall.swf"
 });
 //Create Bar Chart
 var barChart = new YAHOO.widget.BarChart( "barchart", myDataSource,
 {
   series:barChartSeriesDef,
   yField: "month",
   xAxis: currencyAxis,
   dataTipFunction: YAHOO.example.getXAxisDataTipText,
   //only needed for flash player express install
   expressInstall: "yui_2.7.0b-assets/charts-assets/expressinstall.swf"
 });
 //Create Column Chart
 var columnChart = new YAHOO.widget.ColumnChart( "columnchart", myDataSource,
 {
   series: seriesDef,
   xField: "month",
   yAxis: currencyAxis,
   dataTipFunction: YAHOO.example.getYAxisDataTipText,
   //only needed for flash player express install
   expressInstall: "yui_2.7.0b-assets/charts-assets/expressinstall.swf"
 });

</script>

</body>

 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Charts Quickstart Example

   <source lang="html4strict">


<head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Charts Quickstart Example</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="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/json/json-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/datasource/datasource-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/charts/charts-min.js"></script>


<style type="text/css">

 #chart
 {
   width: 500px;
   height: 350px;
 }
 .chart_title
 {
   display: block;
   font-size: 1.2em;
   font-weight: bold;
   margin-bottom: 0.4em;
 }

</style>

</head> <body class=" yui-skin-sam">

Charts Quickstart Example

This example is a demonstration of the <a href="http://developer.yahoo.ru/yui/charts/">YUI Chart Control</a>"s basic features.

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.

Monthly Expenses

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.</p>

<script type="text/javascript">

 YAHOO.widget.Chart.SWFURL = "yui_2.7.0b-lib/charts/assets/charts.swf";

//--- data

 YAHOO.example.monthlyExpenses =
 [
   { month: "January", rent: 880.00, utilities: 894.68 },
   { month: "February", rent: 880.00, utilities: 901.35 },
   { month: "March", rent: 880.00, utilities: 889.32 },
   { month: "April", rent: 880.00, utilities: 884.71 },
   { month: "May", rent: 910.00, utilities: 879.811 },
   { month: "June", rent: 910.00, utilities: 897.95 }
 ];
 var myDataSource = new YAHOO.util.DataSource( YAHOO.example.monthlyExpenses );
 myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
 myDataSource.responseSchema =
 {
   fields: [ "month", "rent", "utilities" ]
 };

//--- chart

 var seriesDef =
 [
   { displayName: "Rent", yField: "rent" },
   { displayName: "Utilities", yField: "utilities" }
 ];
 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( item[series.yField] );
   return toolTipText;
 }
 var currencyAxis = new YAHOO.widget.NumericAxis();
 currencyAxis.minimum = 800;
 currencyAxis.labelFunction = YAHOO.example.formatCurrencyAxisLabel;
 var mychart = new YAHOO.widget.LineChart( "chart", myDataSource,
 {
   series: seriesDef,
   xField: "month",
   yAxis: currencyAxis,
   dataTipFunction: YAHOO.example.getDataTipText,
   //only needed for flash player express install
   expressInstall: "yui_2.7.0b-assets/charts-assets/expressinstall.swf"
 });

</script>

</body>

 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Chart with DataSource Polling

   <source lang="html4strict">


<head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Chart with DataSource Polling</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="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/json/json-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/connection/connection-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/datasource/datasource-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/charts/charts-min.js"></script>


<style type="text/css">

 #chart
 {
   width: 500px;
   height: 350px;
 }
 
 .chart_title
 {
   display: block;
   font-size: 1.2em;
   font-weight: bold;
   margin-bottom: 0.4em;
 }

</style>

</head> <body class=" yui-skin-sam">

Chart with DataSource Polling

The <a href="http://developer.yahoo.ru/yui/charts/">YUI Charts Control</a> provides built-in support for iterative polling for data over XHR using an XHR <a href="http://developer.yahoo.ru/yui/datasource/">DataSource</a> instance. In the example below, iterative polling causes the chart to refresh every several seconds and animate its display to represent the new data.

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.</p>

<script type="text/javascript">

 YAHOO.widget.Chart.SWFURL = "yui_2.7.0b-lib/charts/assets/charts.swf";

//--- data

 var jsonData = new YAHOO.util.DataSource( "yui_2.7.0b-assets/charts-assets/generatedata.php?" );
 //use POST so that IE doesn"t cache the data
 jsonData.connMethodPost = true;
 jsonData.responseType = YAHOO.util.DataSource.TYPE_JSON;
 jsonData.responseSchema =
 {
     resultsList: "Results",
     fields: ["Name","Value"]
 };

//--- chart

 var yAxis = new YAHOO.widget.NumericAxis();
 yAxis.minimum = 0;
 yAxis.maximum = 100;
 var mychart = new YAHOO.widget.ColumnChart( "chart", jsonData,
 {
   xField: "Name",
   yField: "Value",
   yAxis: yAxis,
   polling: 2000,
   //only needed for flash player express install
   expressInstall: "yui_2.7.0b-assets/charts-assets/expressinstall.swf"
 });

</script>

</body>

 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Chart with Legend Example

   <source lang="html4strict">


<head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Chart with Legend Example</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="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/json/json-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/datasource/datasource-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/charts/charts-min.js"></script>


<style type="text/css">

 #chart
 {
   float: left;
   width: 450px;
   height: 300px;
 }
 .chart_title
 {
   display: block;
   font-size: 1.2em;
   font-weight: bold;
   margin-bottom: 0.4em;
 }

</style>

</head> <body class=" yui-skin-sam">

Chart with Legend Example

A legend may be displayed with the <a href="http://developer.yahoo.ru/yui/charts/">YUI Charts Control</a> by setting a few simple styles. This example shows you how.

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.

Survey: What is your favorite season?

Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can install the latest version at the <a href="http://www.adobe.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.</p>

<script type="text/javascript">

 YAHOO.widget.Chart.SWFURL = "yui_2.7.0b-lib/charts/assets/charts.swf";

//--- data

 YAHOO.example.publicOpinion =
 [
   { response: "Summer", count: 564815 },
   { response: "Fall", count: 664182 },
   { response: "Spring", count: 248124 },
   { response: "Winter", count: 271214 },
   { response: "Undecided", count: 81845 }
 ]
 var opinionData = new YAHOO.util.DataSource( YAHOO.example.publicOpinion );
 opinionData.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
 opinionData.responseSchema = { fields: [ "response", "count" ] };

//--- chart

 var mychart = new YAHOO.widget.PieChart( "chart", opinionData,
 {
   dataField: "count",
   categoryField: "response",
   style:
   {
     padding: 20,
     legend:
     {
       display: "right",
       padding: 10,
       spacing: 5,
       font:
       {
         family: "Arial",
         size: 13
       }
     }
   },
   //only needed for flash player express install
   expressInstall: "yui_2.7.0b-assets/charts-assets/expressinstall.swf"
 });

</script>

</body>

 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Column Chart with Rotated Title and Labels

   <source lang="html4strict">


<head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Column Chart with Rotated Title and Labels</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="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/json/json-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/datasource/datasource-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/charts/charts-min.js"></script>


<style type="text/css">

 #chart
 {
   width: 500px;
   height: 350px;
 }
 .chart_title
 {
   display: block;
   font-size: 1.2em;
   font-weight: bold;
   margin-bottom: 0.4em;
 }

</style>

</head> <body class=" yui-skin-sam">

Column Chart with Rotated Title and Labels

Axes Title and Label fields can be rotated on the <a href="http://developer.yahoo.ru/yui/charts/">YUI Charts Control</a> by setting the titleRotation and labelRotation axis styles. This example shows you how.

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.


Monthly Expenses

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.</p>

<script type="text/javascript">

 YAHOO.widget.Chart.SWFURL = "yui_2.7.0b-lib/charts/assets/charts.swf";

//--- data

 YAHOO.example.monthlyExpenses =
 [
   { month: "January", rent: 1350.00, utilities: 941.68 },
   { month: "February", rent: 1350.00, utilities: 901.35 },
   { month: "March", rent: 1350.00, utilities: 789.32 },
   { month: "April", rent: 1350.00, utilities: 684.71 },
   { month: "May", rent: 1500.00, utilities: 779.811 },
   { month: "June", rent: 1500.00, utilities: 897.95 },
   { month: "July", rent: 1500.00, utilities: 919.811 },
   { month: "August", rent: 1500.00, utilities: 937.95 },
   { month: "September", rent: 1500.00, utilities: 779.811 },
   { month: "October", rent: 1500.00, utilities: 697.95 },
   { month: "November", rent: 1500.00, utilities: 679.811 },
   { month: "December", rent: 1500.00, utilities: 897.95 }
 ];
 var myDataSource = new YAHOO.util.DataSource( YAHOO.example.monthlyExpenses );
 myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
 myDataSource.responseSchema =
 {
   fields: [ "month", "rent", "utilities" ]
 };

//--- chart

 //series definition for chart
 var seriesDef =
 [
   {
     displayName: "Rent",
     yField: "rent",
     style:{size:10}
   },
   {
     displayName: "Utilities",
     yField: "utilities",
     style:{size:10}
   }
 ];
 //Style object for chart
 var styleDef =
 {
   xAxis:
   {
     labelRotation:-90
   },
   yAxis:
   {
     titleRotation:-90
   }
 }
 //format currency
 YAHOO.example.formatCurrencyAxisLabel = function( value )
 {
   return YAHOO.util.Number.format( value,
   {
     prefix: "$",
     thousandsSeparator: ",",
     decimalPlaces: 2
   });
 }
 //DataTip function for the chart
 YAHOO.example.getDataTipText = function( item, index, series )
 {
   var toolTipText = series.displayName + " for " + item.month;
   toolTipText += "\n" + YAHOO.example.formatCurrencyAxisLabel( item[series.yField] );
   return toolTipText;
 }
 //create a Numeric Axis for displaying dollars
 var currencyAxis = new YAHOO.widget.NumericAxis();
 currencyAxis.labelFunction = YAHOO.example.formatCurrencyAxisLabel;
 currencyAxis.title = "Money Spent";
 //create Category Axis to specify a title for the months
 var categoryAxis = new YAHOO.widget.CategoryAxis();
 categoryAxis.title = "Month";
 //create a Chart
 var mychart = new YAHOO.widget.ColumnChart( "chart", myDataSource,
 {
   series: seriesDef,
   xField: "month",
   yAxis: currencyAxis,
   xAxis: categoryAxis,
   style: styleDef,
   dataTipFunction: YAHOO.example.getDataTipText,
   //only needed for flash player express install
   expressInstall: "yui_2.7.0b-assets/charts-assets/expressinstall.swf"
 });

</script>

</body>

 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Skinning a Chart

   <source lang="html4strict">

<head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Skinning a Chart Example</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="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/json/json-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/datasource/datasource-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/charts/charts-min.js"></script>


<style type="text/css">

 #chart
 {
   width: 580px;
   height: 400px;
 }
 
 .chart_title
 {
   display: block;
   font-size: 1.2em;
   font-weight: bold;
   margin-bottom: 0.4em;
 }

</style>

</head> <body class=" yui-skin-sam">

Skinning a Chart Example

This example demonstrates how to modify the <a href="http://developer.yahoo.ru/yui/charts/">YUI Charts Control</a>"s styles to give it a custom appearance.

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.

Wilson"s Supermarket - Product Comparison

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.</p>

<script type="text/javascript">

 YAHOO.widget.Chart.SWFURL = "yui_2.7.0b-lib/charts/assets/charts.swf";

//--- data

 YAHOO.example.salesComparison =
 [
   { month: "Oct", pork: 1354, beef: 1442 },
   { month: "Nov", pork: 1326, beef: 1496 },
   { month: "Dec", pork: 1292, beef: 1582 },
   { month: "Jan", pork: 1387, beef: 1597 },
   { month: "Feb", pork: 1376, beef: 1603 }
 ];
 var salesData = new YAHOO.util.DataSource( YAHOO.example.salesComparison );
 salesData.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
 salesData.responseSchema = { fields: [ "month", "pork", "beef" ] };

//--- chart

 var seriesDef =
 [
   {
     yField: "pork",
     displayName: "Sales of Pork",
     style:
     {
       image: "yui_2.7.0b-assets/charts-assets/tube.png",
       mode: "no-repeat",
       color: 0x2e434d,
       size: 40
     }
   },
   {
     yField: "beef",
     displayName: "Sales of Beef",
     style:
     {
       image: "yui_2.7.0b-assets/charts-assets/tube.png",
       mode: "no-repeat",
       color: 0xc2d81e,
       size: 40
     }
   }
 ];
 var mychart = new YAHOO.widget.ColumnChart( "chart", salesData,
 {
   series: seriesDef,
   xField: "month",
   style:
   {
     border: {color: 0x96acb4, size: 12},
     font: {name: "Arial Black", size: 14, color: 0x586b71},
     dataTip:
     {
       border: {color: 0x2e434d, size: 2},
       font: {name: "Arial Black", size: 13, color: 0x586b71}
     },
     xAxis:
     {
       color: 0x2e434d
     },
     yAxis:
     {
       color: 0x2e434d,
       majorTicks: {color: 0x2e434d, length: 4},
       minorTicks: {color: 0x2e434d, length: 2},
       majorGridLines: {size: 0}
     }
   },
   //only needed for flash player express install
   expressInstall: "yui_2.7.0b-assets/charts-assets/expressinstall.swf"
 });

</script>

</body>

 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Stacked Bar Chart

   <source lang="html4strict">


<head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Stacked Bar Chart</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="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/json/json-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/datasource/datasource-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/charts/charts-min.js"></script>


<style type="text/css">

 #chart
 {
   width: 500px;
   height: 350px;
 }
 .chart_title
 {
   display: block;
   font-size: 1.2em;
   font-weight: bold;
   margin-bottom: 0.4em;
 }

</style>

</head> <body class=" yui-skin-sam">

Stacked Bar Chart

This example demonstrates how to use <a href="http://developer.yahoo.ru/yui/charts/">YUI Charts Control</a> to create a Stacked Bar Chart.

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.

Media Conglomerate Ad Sales Summary 2004-2007

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.</p>

<script type="text/javascript">

 YAHOO.widget.Chart.SWFURL = "yui_2.7.0b-lib/charts/assets/charts.swf";

//--- data

 YAHOO.example.annualSales =
 [
   { year: 2004, internetsales: 246852, printsales: 2523359, tvsales: 3123493 },
   { year: 2005, internetsales: 851876, printsales: 1084952, tvsales: 3166920 },
   { year: 2006, internetsales: 3917246, printsales: 587151, tvsales: 2330095 },
   { year: 2007, internetsales: 5318185, printsales: 307456, tvsales: 1830729 }
 ];
 var salesData = new YAHOO.util.DataSource( YAHOO.example.annualSales );
 salesData.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
 salesData.responseSchema = { fields: [ "year", "internetsales", "printsales", "tvsales" ] };

//--- chart

 var seriesDef =
 [
   {
     xField: "internetsales",
     displayName: "Internet Sales"
   },
   {
     xField: "printsales",
     displayName: "Print Sales"
   },
   {
     xField: "tvsales",
     displayName: "Television Sales"
   }
 ];
 //used to format x axis
 YAHOO.example.numberToCurrency = function( value )
 {
   return YAHOO.util.Number.format(Number(value), {prefix: "$", thousandsSeparator: ","});
 }
 //Numeric Axis for our currency
 var currencyAxis = new YAHOO.widget.NumericAxis();
 currencyAxis.stackingEnabled = true;
 currencyAxis.labelFunction = YAHOO.example.numberToCurrency;
 var mychart = new YAHOO.widget.StackedBarChart( "chart", salesData,
 {
   series: seriesDef,
   yField: "year",
   xAxis: currencyAxis,
   //only needed for flash player express install
   expressInstall: "yui_2.7.0b-assets/charts-assets/expressinstall.swf"
 });

</script>

</body>

 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Styling Lines, Borders and Fills

   <source lang="html4strict">

<head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Styling Lines, Borders and Fills</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="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/json/json-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/datasource/datasource-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/charts/charts-min.js"></script>


<style type="text/css">

 #chart
 {
   width: 500px;
   height: 350px;
 }
 .chart_title
 {
   display: block;
   font-size: 1.2em;
   font-weight: bold;
   margin-bottom: 0.4em;
 }

</style>

</head> <body class=" yui-skin-sam">

Styling Lines, Borders and Fills

The <a href="http://developer.yahoo.ru/yui/charts/">YUI Charts Control</a> offers customization through its style and series style objects. This example demonstrates one way to customize a Line Chart.

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.


January Daily Profits

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.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.</p>

<script type="text/javascript"> YAHOO.widget.Chart.SWFURL = "yui_2.7.0b-lib/charts/assets/charts.swf"; //--- data

 //revenue and expenses per day
 var dailyFinancials =
 [
   {date:"1/1/2009", revenue:14002, expenses:15000},
   {date:"1/2/2009", revenue:14027, expenses:16527},
   {date:"1/3/2009", revenue:15083, expenses:17283},
   {date:"1/4/2009", revenue:15006, expenses:18694},
   {date:"1/5/2009", revenue:15035, expenses:18235},
   {date:"1/6/2009", revenue:17871, expenses:18371},
   {date:"1/7/2009", revenue:25887, expenses:17787},
   {date:"1/8/2009", revenue:16149, expenses:16149},
   {date:"1/9/2009", revenue:17366, expenses:15666},
   {date:"1/10/2009", revenue:16424, expenses:15776},
   {date:"1/11/2009", revenue:15817, expenses:18717},
   {date:"1/12/2009", revenue:13554, expenses:18154},
   {date:"1/13/2009", revenue:19782, expenses:18182},
   {date:"1/14/2009", revenue:24400, expenses:18600},
   {date:"1/15/2009", revenue:21780, expenses:18480},
   {date:"1/16/2009", revenue:16681, expenses:21581},
   {date:"1/17/2009", revenue:24645, expenses:21745},
   {date:"1/18/2009", revenue:22212, expenses:20388},
   {date:"1/19/2009", revenue:24026, expenses:24726},
   {date:"1/20/2009", revenue:29264, expenses:24864},
   {date:"1/21/2009", revenue:19922, expenses:23622},
   {date:"1/22/2009", revenue:12373, expenses:18773},
   {date:"1/23/2009", revenue:11944, expenses:18444},
   {date:"1/24/2009", revenue:23741, expenses:18641},
   {date:"1/25/2009", revenue:24758, expenses:19758},
   {date:"1/26/2009", revenue:31611, expenses:19611},
   {date:"1/27/2009", revenue:25612, expenses:18212},
   {date:"1/28/2009", revenue:26830, expenses:18330},
   {date:"1/29/2009", revenue:27929, expenses:19029},
   {date:"1/30/2009", revenue:28153, expenses:19953},
   {date:"1/31/2009", revenue:28018, expenses:18118}
 ];
 //calculate profits from revenue and expenses
 function calculateProfits(dataArray)
 {
   var dataLength = dataArray.length;
   for(var i = 0; i < dataLength; i++)
   {
     var dataObj = dataArray[i];
     dataObj.profits = dataObj.revenue - dataObj.expenses;
   }
   return dataArray;
 }
 var myDataSource = new YAHOO.util.DataSource(calculateProfits(dailyFinancials));
 myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
 myDataSource.responseSchema =
 {
   fields:
   [
     "date",
     "expenses",
     "revenue",
     "profits"
   ]
 };

//--- chart

 //series definition
 var seriesDef = [
   {
     displayName:"Expenses",
     yField:"expenses",
     style:
     {
       lineColor:0xB5BAC8,
       lineAlpha:.5,
       borderColor:0xB5BAC8,
       fillColor:0xB5BAC8
     }
   },
   {
     displayName:"Revenue",
     yField:"revenue",
     style:
     {
       lineColor:0xB5BAC8,
       lineAlpha:.5,
       borderColor:0xB5BAC8,
       fillColor:0xffffff
     }
   },
   {
     displayName:"Profits",
     yField:"profits",
     style:
     {
       lineColor:0x79839B,
       borderColor:0x79839B,
       fillColor:0x79839B
     }
   }
 ];
 //Style object
 var styleDef =
 {
   xAxis:
   {
     majorTicks:
     {
       display:"inside",
       length:3,
       size:1
     },
     minorTicks:
     {
       display:"inside",
       length:2
     },
     labelRotation: -90
   },
   yAxis:
   {
     zeroGridLine:
     {
       size:2,
       color:0xff0000
     },
     minorTicks:{display:"none"}
   }
 }
 //format date labels
 YAHOO.example.formatTimeData = function(value, major)
 {
   var formattedData = YAHOO.util.Date.format(new Date(value), {format:"%b %e"});
   return formattedData.toString();
 }
 //format currency labels
 YAHOO.example.formatCurrencyAxisLabel = function( value )
 {
   return YAHOO.util.Number.format( value,
   {
     prefix: "$",
     thousandsSeparator: ",",
     decimalPlaces: 2
   });
 }
 //DataTip function for the chart
 YAHOO.example.formatDataTipText = function(item, index, series)
 {
   var str = series.displayName + " for " + item.date;
   str += "\n" + YAHOO.example.formatCurrencyAxisLabel(item[(series.displayName).toLowerCase()]);
   return str;
 }
 //Create a TimeAxis for displaying dates
 var myTimeAxis = new YAHOO.widget.TimeAxis();
 myTimeAxis.labelFunction = YAHOO.example.formatTimeData;
 myTimeAxis.majorTimeUnit = "day";
 //create a Numeric Axis for displaying dollars
 myCurrencyAxis = new YAHOO.widget.NumericAxis();
 myCurrencyAxis.labelFunction = YAHOO.example.formatCurrencyAxisLabel;
 //create a Chart
 var mychart = new YAHOO.widget.LineChart("chart", myDataSource,
 {
   series: seriesDef,
   style: styleDef,
   xField: "date",
   xAxis: myTimeAxis,
   yAxis: myCurrencyAxis,
   dataTipFunction:YAHOO.example.formatDataTipText,
   //only needed for flash player express install
   expressInstall: "yui_2.7.0b-assets/charts-assets/expressinstall.swf"
 });

</script>

</body>

 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>