Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>

<a href="javascript:void(0);" class="trigger" id="trigger03">▼モバイル端末別の訪問数のグラフを表示する(クリックで表示)▼</a>

<div class="clearfix">

	<div class="group">
		<div class="graph" id="canvas03_wrap">
			
		</div>
		<div class="text" id="canvas03_desc">
      <figure id="canvas03_img_wrap"></figure>
			<p>iPhoneが全体の約68%を占めています。<strong>この68%という数字はイギリスの調査会社Kantar Worldpanel ComTechが1月27日(現地時間)に発表した日本での2013年第4四半期(10~12月)のiOSのシェアとほぼ同じ。</strong> 特にWebNAUTを読んでいただいた方にiPhoneユーザーが多いというわけではないようです。</p>
		</div>
	</div>

</div>
              
            
!

CSS

              
                body {
  text-align: center;
  width: 540px;
  margin: 20px auto;
  padding: 0 10px;
  a.trigger {
      display: inline-block;
      color: #fff !important;
      background-color: rgba(32,186,238,1);
      border-radius: 8px;
      padding: 5px 20px;
      text-align: center;
      margin-bottom: 10px;
  }

  #canvas03_wrap {
    display: inline-block;
    clear: both;
  }
  #canvas03_img_wrap {
    position: relative;
    margin-left: -20px;
  }
  #canvas03_desc {
    display: inline-block;
    text-align: left;
  }
}
              
            
!

JS

              
                $(function(){

/*save objects*/
var canvas = {
    "canvas02" : null
}
var colors = {
    "01a" : "rgba(10,25,215,1)",
    "01b" : "rgba(32,186,238,1)",
    "02a" : "rgba(245,70,53,1)",
    "02b" : "rgba(255,241,0,1)",
    "02c" : "rgba(215,10,25,0.2)",
    "03a" : "rgba(32,186,238,0.5)",
    "03b" : "rgba(245,70,53,0.5)",
    "04a" : "rgba(215,215,215,1)",
    "05a" : "rgba(245,70,53,0.8)",
    "05b" : "rgba(255,241,0,0.5)",
}


/*
@CANVAS
drawing graphs
augument : canvas要素のidの連番、グラフの種類、chart.jsに渡す引数のオブジェクトを格納した配列
戻り値:なし
*/
function CANVAS(_SET){
    var vals = null;
    var descId = "";
    var options = null;

    fire = (function(_SET){
        if(_SET.id){
            descId = _SET.id;
        }
        if(_SET.vals){
            vals = _SET.vals;
        }
        if(_SET.options){
            options = _SET.options;
        }
        var canvas = document.getElementById(_SET.id).getContext("2d");
        if(_SET.type){
            switch(_SET.type){
                case "Doughnut":
                    var draw = new Chart(canvas).Doughnut(vals,options);
                    break;
                case "Bar":
                    var draw = new Chart(canvas).Bar(vals,options);
                    break;
                case "Line":
                    var draw = new Chart(canvas).Line(vals,options);
                    break;
                case "Radar":
                    var draw = new Chart(canvas).Radar(vals,options);
                    break;
                case "PolarArea":
                    var draw = new Chart(canvas).PolarArea(vals,options);
                    break;
                case "Pie":
                    var draw = new Chart(canvas).Pie(vals,options);
                    break;
                default : return false;
                    break;
            }
        }
    })(_SET);
    
};



function start(_SET){
    canvas["canvas"+_SET.id] = new CANVAS(_SET);
}


/*

on window.load

*/
$(function(){
    
    $("div.text").css("opacity","0");

    var insertObj03 = $("<canvas>").attr({
      "id" : "canvas03",
      "width" : 400,
      "height" : 330
    });
    $("#canvas03_wrap").append(insertObj03);

    var insertObj02 = $("<img>").attr({
      "src" : "http://webnaut.jp/develop/img/img_develop_140203_01_b.png",
      "alt" : "デバイス別の訪問数 サンプル"
    });
    $("#canvas03_img_wrap").append(insertObj02);
    
});

/*

trigger

*/

$("#trigger03").on("click",
    function(){
        var _SET = {
            id : "canvas03",
            type : "Doughnut",
            vals : [
                {
                    value: 68.58,
                    color: colors["01b"]
                },
                {
                    value: 7.13,
                    color: colors["02a"]
                },
                {
                    value: 3.79,
                    color: colors["02b"]
                },
                {
                    value: 1.93,
                    color: colors["03a"]
                },
                {
                    value: 1.05,
                    color: colors["03b"]
                },
                {
                    value: 17.52,
                    color: colors["04a"]
                }

            ],
            options : {
                animationSteps : 100,
                onAnimationComplete : function(){
                        $("#"+_SET.id+"_desc").animate({
                            "opacity" : 1
                        },600,"linear");
                }
            }
        }

        start(_SET);
    }
);

});

              
            
!
999px

Console