|
| 1 | +<!DOCTYPE html> |
| 2 | +<meta charset="utf-8"> |
| 3 | + |
| 4 | +<svg id="chart-svg"></svg> |
| 5 | + |
| 6 | + |
| 7 | +<style> |
| 8 | + |
| 9 | +text { |
| 10 | + font: 12px sans-serif; |
| 11 | +} |
| 12 | + |
| 13 | +</style> |
| 14 | +<body> |
| 15 | +<script src="d3.v2.js"></script> |
| 16 | +<!-- <script src="nvd3.js"></script> --> |
| 17 | + |
| 18 | +<script> |
| 19 | + |
| 20 | +function ageRanges(){ |
| 21 | + return ["Under 18", "18-24", "25-32", "33-40", "41-50", "51-60", "Over 60"] |
| 22 | +} |
| 23 | + |
| 24 | +function getDashboardPieColors() { |
| 25 | + return ['#71c857', '#4ca233', '#51c199', '#51c175', '#85db02', '#7d886c', '#8df26f', '#454a44' ]; |
| 26 | +} |
| 27 | + |
| 28 | + |
| 29 | +var socialq = {} |
| 30 | +socialq.models = {} |
| 31 | + |
| 32 | +socialq.models.pie = function() { |
| 33 | + function chart(selection){ |
| 34 | + selection.each(function(data){ |
| 35 | + |
| 36 | + }); |
| 37 | + } |
| 38 | + return chart; |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +socialq.pieChart = function() { |
| 43 | + var width = 720 |
| 44 | + ,height = 80 |
| 45 | + ,margin = { top : 20, bottom : 20, left : 20, right : 20 } |
| 46 | + ,pie = socialq.models.pie() |
| 47 | + ; |
| 48 | + |
| 49 | + |
| 50 | + function chart(selection){ |
| 51 | + selection.each(function(data){ |
| 52 | + var svg_container = d3.select(this); |
| 53 | + // container.selectAll('g.nv-wrap.nv-pieChart') |
| 54 | + // .data([1]) |
| 55 | + // .enter() |
| 56 | + // .append('g') |
| 57 | + // .attr('class','pie-chart-wrapper') |
| 58 | + }) |
| 59 | + } |
| 60 | + chart.width = function(value) { |
| 61 | + if (!arguments.length) return width; |
| 62 | + width = value; |
| 63 | + return my; |
| 64 | + }; |
| 65 | + |
| 66 | + chart.height = function(value) { |
| 67 | + if (!arguments.length) return height; |
| 68 | + height = value; |
| 69 | + return my; |
| 70 | + }; |
| 71 | + |
| 72 | + return chart; |
| 73 | +} |
| 74 | + |
| 75 | +var myChart = socialq.pieChart(); |
| 76 | + |
| 77 | +var container = d3.select("#chart-svg") |
| 78 | + .datum([1,2,3,4,5]) |
| 79 | + .call(myChart) |
| 80 | + |
| 81 | + |
| 82 | +// var width = 250, |
| 83 | +// height = 400, |
| 84 | +// margin = { top : 20, bottom: 20, left:20, right: 20} |
| 85 | +// radius = Math.min(width, height) / 2, |
| 86 | +// data = d3.range(10).map(Math.random).sort(d3.descending).slice(0,ageRanges().length), |
| 87 | +// color = getDashboardPieColors(), |
| 88 | +// arc = d3.svg.arc().outerRadius(radius), |
| 89 | +// dispatch = d3.dispatch('legendClick', 'legendDblclick', 'legendMouseover', 'legendMouseout'), |
| 90 | +// donut = d3.layout.pie(); |
| 91 | +// |
| 92 | +// var xxx = test_chart(); |
| 93 | +// var data = [1,2,3,4,5,6]; |
| 94 | +// |
| 95 | +// var container = d3.select("body").append("svg") |
| 96 | +// .data(data) |
| 97 | +// .attr("class", "chart") |
| 98 | +// |
| 99 | +// var container = d3.select("body").append("svg") |
| 100 | +// .datum(data) |
| 101 | +// .attr("class", "chart") |
| 102 | + |
| 103 | + |
| 104 | + // var wrap = container.select('g.nv-wrap.nv-pieChart') |
| 105 | + // .datum([data]) |
| 106 | + // .append('g') |
| 107 | + // .attr('class','pie-chart-wrapper') |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + // var wrap = container.selectAll('g.nv-wrap.nv-pieChart') |
| 117 | + // .data([data]); |
| 118 | + // |
| 119 | + // var gEnter = wrap.enter().append('g') |
| 120 | + // .attr('class', 'nvd3 nv-wrap nv-pieChart') |
| 121 | + // .append('g'); |
| 122 | + // |
| 123 | + // var g = wrap.select('g'); |
| 124 | + // |
| 125 | + // gEnter.append('g').attr('class', 'nv-pieWrap'); |
| 126 | + // gEnter.append('g').attr('class', 'nv-legendWrap'); |
| 127 | + // |
| 128 | + // // pie charts |
| 129 | + // |
| 130 | + // wrap.select('.nv-pieWrap') |
| 131 | + // .data(donut) |
| 132 | + // .enter().append("g") |
| 133 | + // .attr("class", "arc") |
| 134 | + // .attr("transform", "translate(" + radius + "," + radius + ")"); |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | +</script> |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | + |
0 commit comments