src/cm/media/js/lib/yui/yui_3.10.3/docs/charts/charts-objectstyles.html
author Yves-Marie Haussonne <ymh.work+github@gmail.com>
Fri, 09 May 2014 18:35:26 +0200
changeset 656 a84519031134
parent 525 89ef5ed3c48b
permissions -rw-r--r--
add link to "privacy policy" in the header test

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example: Define a Chart&#x27;s Axes and Series</title>
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
    <link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
    <script src="../../build/yui/yui-min.js"></script>
    
</head>
<body>
<!--
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
-->
<div id="doc">
    <div id="hd">
        <h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
    </div>
    

            <h1>Example: Define a Chart&#x27;s Axes and Series</h1>
    <div class="yui3-g">
        <div class="yui3-u-3-4">
            <div id="main">
                <div class="content"><style scoped>
#mychart {
    margin:10px 10px 10px 10px;
    width:90%;
    max-width: 800px;
    height:400px;
}
</style>
<div class="intro">
<p>This example shows how to explicitly define the axes and series for a <code>Chart</code>.</p>
</div>
<div class="example">
<div id="mychart"></div>
<script type="text/javascript">
(function() {
    YUI().use('charts', function (Y) 
    { 
        //dataProvider source
        var myDataValues = [ 
            {date:"1/1/2010", miscellaneous:2000, expenses:3700, revenue:2200}, 
            {date:"2/1/2010", miscellaneous:5000, expenses:9100, revenue:100}, 
            {date:"3/1/2010", miscellaneous:4000, expenses:1900, revenue:1500}, 
            {date:"4/1/2010", miscellaneous:3000, expenses:3900, revenue:2800}, 
            {date:"5/1/2010", miscellaneous:500, expenses:7000, revenue:2650},
            {date:"6/1/2010", miscellaneous:3000, expenses:4700, revenue:1200} 
        ];
        
        //Define our axes for the chart.
        var myAxes = {
            financials:{
                keys:["miscellaneous", "revenue", "expenses"],
                position:"right",
                type:"numeric",
                styles:{
                    majorTicks:{
                        display: "none"
                    }
                }
            },
            dateRange:{
                keys:["date"],
                position:"bottom",
                type:"category",
                styles:{
                    majorTicks:{
                        display: "none"
                    },
                    label: {
                        rotation:-45,
                        margin:{top:5}
                    }
                }
            }
        };
       
        //define the series 
        var seriesCollection = [
         {
                type:"column",
                xAxis:"dateRange",
                yAxis:"financials",
                xKey:"date",
                yKey:"miscellaneous",
                xDisplayName:"Date",
                yDisplayName:"Miscellaneous",
                styles: {
                    border: {
                        weight: 1,
                        color: "#58006e"
                    },
                    over: {
                        fill: {
                            alpha: 0.7
                        }
                    }
                }
            },
            {
                type:"column",
                xAxis:"dateRange",
                yAxis:"financials",
                xKey:"date",
                xDisplayName:"Date",
                yKey:"expenses",
                yDisplayName:"Expenses",
                styles: {
                    marker:{
                        fill: {
                            color: "#e0ddd0" 
                        },
                        border: {
                            weight: 1,
                            color: "#cbc8ba"
                        },
                        over: {
                            fill: {
                                alpha: 0.7
                            }
                        }
                    }
                }
            },
            {
                type:"combo",
                xAxis:"dateRange",
                yAxis:"financials",
                xKey:"date",
                xDisplayName:"Date",
                yKey:"revenue",
                xDisplayName:"Date",
                yDisplayName:"Deductions",
                    line: {
                        color: "#ff7200"
                    },
                marker: {
                    fill: {
                        color: "#ff9f3b"
                    },
                    border: {
                        color: "#ff7200",
                        weight: 1
                    },
                    over: {
                        width: 12,
                        height: 12
                    },
                    width:9,
                    height:9
                }
            }
        ];

        //instantiate the chart
        var myChart = new Y.Chart({
                            dataProvider:myDataValues, 
                            axes:myAxes, 
                            seriesCollection:seriesCollection, 
                            horizontalGridlines: true,
                            verticalGridlines: true,
                            render:"#mychart"
                        });
    });
})();
</script>

</div>
<h3>Defining the axes and series for a <code>Chart</code> instance</h3>

<p>As we have seen from previous examples, the <code>Chart</code> class allows you to create and customize multiple chart types with very little code. Sometimes you'll want more control 
over the <code>Chart</code>. Suppose you want to place your value axis on the right or you need different series types in the same chart. Charts allows you to explicitly define your series and axes objects. You can either declare
an axis or series directly or define them with an object literal and allow the <code>Chart</code> instance to build them for you. In this example, we are going to define our axes and series with
object literals. This will allow us to place our value axis on the right and build a chart with columns and lines.</p>

<h4>CSS</h4>
<pre class="code prettyprint">#mychart {
    margin:10px 10px 10px 10px;
    width:90%;
    max-width: 800px;
    height:400px;
}</pre>


<h4>HTML</h4>
<pre class="code prettyprint">&lt;div id=&quot;mychart&quot;&gt;&lt;&#x2F;div&gt;</pre>


<h4>JavaScript</h4>
<pre class="code prettyprint">YUI().use(&#x27;charts&#x27;, function (Y) 
{ 
    &#x2F;&#x2F;dataProvider source
    var myDataValues = [ 
        {date:&quot;1&#x2F;1&#x2F;2010&quot;, miscellaneous:2000, expenses:3700, revenue:2200}, 
        {date:&quot;2&#x2F;1&#x2F;2010&quot;, miscellaneous:5000, expenses:9100, revenue:100}, 
        {date:&quot;3&#x2F;1&#x2F;2010&quot;, miscellaneous:4000, expenses:1900, revenue:1500}, 
        {date:&quot;4&#x2F;1&#x2F;2010&quot;, miscellaneous:3000, expenses:3900, revenue:2800}, 
        {date:&quot;5&#x2F;1&#x2F;2010&quot;, miscellaneous:500, expenses:7000, revenue:2650},
        {date:&quot;6&#x2F;1&#x2F;2010&quot;, miscellaneous:3000, expenses:4700, revenue:1200} 
    ];

    &#x2F;&#x2F;Define our axes for the chart.
    var myAxes = {
        financials:{
            keys:[&quot;miscellaneous&quot;, &quot;revenue&quot;, &quot;expenses&quot;],
            position:&quot;right&quot;,
            type:&quot;numeric&quot;,
            styles:{
                majorTicks:{
                    display: &quot;none&quot;
                }
            }
        },
        dateRange:{
            keys:[&quot;date&quot;],
            position:&quot;bottom&quot;,
            type:&quot;category&quot;,
            styles:{
                majorTicks:{
                    display: &quot;none&quot;
                },
                label: {
                    rotation:-45,
                    margin:{top:5}
                }
            }
        }
    };

    &#x2F;&#x2F;define the series 
    var seriesCollection = [
     {
            type:&quot;column&quot;,
            xAxis:&quot;dateRange&quot;,
            yAxis:&quot;financials&quot;,
            xKey:&quot;date&quot;,
            xDisplayName:&quot;Date&quot;,
            yKey:&quot;miscellaneous&quot;,
            xDisplayName:&quot;Date&quot;,
            yDisplayName:&quot;Miscellaneous&quot;,
            styles: {
                border: {
                    weight: 1,
                    color: &quot;#58006e&quot;
                },
                over: {
                    fill: {
                        alpha: 0.7
                    }
                }
            }
        },
        {
            type:&quot;column&quot;,
            xAxis:&quot;dateRange&quot;,
            yAxis:&quot;financials&quot;,
            xKey:&quot;date&quot;,
            xDisplayName:&quot;Date&quot;,
            yKey:&quot;expenses&quot;,
            yDisplayName:&quot;Expenses&quot;,
            styles: {
                marker:{
                    fill: {
                        color: &quot;#e0ddd0&quot; 
                    },
                    border: {
                        weight: 1,
                        color: &quot;#cbc8ba&quot;
                    },
                    over: {
                        fill: {
                            alpha: 0.7
                        }
                    }
                }
            }
        },
        {
            type:&quot;combo&quot;,
            xAxis:&quot;dateRange&quot;,
            yAxis:&quot;financials&quot;,
            xKey:&quot;date&quot;,
            xDisplayName:&quot;Date&quot;,
            yKey:&quot;revenue&quot;,
            xDisplayName:&quot;Date&quot;,
            yDisplayName:&quot;Deductions&quot;,
                line: {
                    color: &quot;#ff7200&quot;
                },
            marker: {
                fill: {
                    color: &quot;#ff9f3b&quot;
                },
                border: {
                    color: &quot;#ff7200&quot;,
                    weight: 1
                },
                over: {
                    width: 12,
                    height: 12
                },
                width:9,
                height:9
            }
        }
    ];
    
    &#x2F;&#x2F;instantiate the chart
    var myChart = new Y.Chart({
                        dataProvider:myDataValues, 
                        axes:myAxes, 
                        seriesCollection:seriesCollection, 
                        horizontalGridlines: true,
                        verticalGridlines: true,
                        render:&quot;#mychart&quot;
                    });
});</pre>

</div>
            </div>
        </div>

        <div class="yui3-u-1-4">
            <div class="sidebar">
                

                
                    <div class="sidebox">
                        <div class="hd">
                            <h2 class="no-toc">Examples</h2>
                        </div>

                        <div class="bd">
                            <ul class="examples">
                                
                                    
                                        <li data-description="Shows how to use Charts to create a basic chart.">
                                            <a href="charts-simple.html">Basic Charts Implementation</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to create a chart with multiple series.">
                                            <a href="charts-multiseries.html">Chart with Multiple Series</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to create a column chart with multiple series.">
                                            <a href="charts-column.html">Specify Chart Type</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to create a column chart with a stacked numeric axis.">
                                            <a href="charts-stackedcolumn.html">Create Stacked Chart</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to create a chart with a time axis.">
                                            <a href="charts-timeaxis.html">Create a Chart with a Time Axis</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to add gridlines to a chart.">
                                            <a href="charts-gridlines.html">Add Gridlines to a Chart</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to create a chart with planar based events.">
                                            <a href="charts-stackedarea.html">Create a Stacked Area Chart with Planar Based Events</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to use a chart&#x27;s styles attribute to customize a chart.">
                                            <a href="charts-globalstyles.html">Customize a Chart</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to customize the default tooltip of a chart.">
                                            <a href="charts-customizedtooltip.html">Customize a Chart&#x27;s Tooltip</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to explicitly define the axes and series for a chart.">
                                            <a href="charts-objectstyles.html">Define a Chart&#x27;s Axes and Series</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to use charts to create a pie chart.">
                                            <a href="charts-pie.html">Pie Chart</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to create a chart with multiple value axes.">
                                            <a href="charts-dualaxes.html">Dual Axes Chart</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to access a chart instance&#x27;s value axis after the chart has rendered.">
                                            <a href="charts-axisupdate.html">Update Chart Axis</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to access a chart instance&#x27;s seriesCollection after the chart has rendered.">
                                            <a href="charts-seriesupdate.html">Update Chart Series</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to add a legend to a chart.">
                                            <a href="charts-legend.html">Create Chart with a Legend</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to render multiple data points in a singe marker.">
                                            <a href="charts-groupmarkers.html">Group Marker Chart</a>
                                        </li>
                                    
                                
                            </ul>
                        </div>
                    </div>
                

                
            </div>
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

<script>
YUI.Env.Tests = {
    examples: [],
    project: '../assets',
    assets: '../assets/charts',
    name: 'charts-objectstyles',
    title: 'Define a Chart&#x27;s Axes and Series',
    newWindow: '',
    auto:  false 
};
YUI.Env.Tests.examples.push('charts-simple');
YUI.Env.Tests.examples.push('charts-multiseries');
YUI.Env.Tests.examples.push('charts-column');
YUI.Env.Tests.examples.push('charts-stackedcolumn');
YUI.Env.Tests.examples.push('charts-timeaxis');
YUI.Env.Tests.examples.push('charts-gridlines');
YUI.Env.Tests.examples.push('charts-stackedarea');
YUI.Env.Tests.examples.push('charts-globalstyles');
YUI.Env.Tests.examples.push('charts-customizedtooltip');
YUI.Env.Tests.examples.push('charts-objectstyles');
YUI.Env.Tests.examples.push('charts-pie');
YUI.Env.Tests.examples.push('charts-dualaxes');
YUI.Env.Tests.examples.push('charts-axisupdate');
YUI.Env.Tests.examples.push('charts-seriesupdate');
YUI.Env.Tests.examples.push('charts-legend');
YUI.Env.Tests.examples.push('charts-groupmarkers');

</script>
<script src="../assets/yui/test-runner.js"></script>



</body>
</html>