123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- /*---- placeholder1----*/
- $(function() {
- 'use strict'
- var sin = [],
- cos = [];
- for (var i = 0; i < 14; i += 0.1) {
- sin.push([i, Math.sin(i)]);
- cos.push([i, Math.cos(i)]);
- }
- var plot = $.plot("#placeholder1", [{
- data: sin
- }, {
- data: cos
- }], {
- series: {
- lines: {
- show: true
- }
- },
- lines: {
- show: true,
- fill: true,
- fillColor: {
- colors: [{
- opacity: 0.7
- }, {
- opacity: 0.7
- }]
- }
- },
- crosshair: {
- mode: "x"
- },
- grid: {
- hoverable: false,
- autoHighlight: false,
- borderColor: "rgba(119, 119, 142, 0.1)",
- verticalLines: false,
- horizontalLines: false
- },
- colors: ['#6c5ffc', '#05c3fb'],
- yaxis: {
- min: -1.2,
- max: 1.2,
- tickLength: 0
- },
- xaxis: {
- tickLength: 0
- }
- });
-
- });
- /*---- placeholder2----*/
- $(function() {
- 'use strict'
- var sin = [],
- cos = [];
- for (var i = 0; i < 14; i += 0.5) {
- sin.push([i, Math.sin(i)]);
- cos.push([i, Math.cos(i)]);
- }
- var plot = $.plot("#placeholder2", [{
- data: sin,
- label: "data1"
- }, {
- data: cos,
- label: "data2"
- }], {
- series: {
- lines: {
- show: true
- },
- points: {
- show: true
- }
- },
- grid: {
- hoverable: true,
- clickable: true,
- borderColor: "rgba(119, 119, 142, 0.1)",
- verticalLines: false,
- horizontalLines: false
- },
- colors: ['#6c5ffc', '#05c3fb'],
- yaxis: {
- min: -1.2,
- max: 1.2,
- tickLength: 0
- },
- xaxis: {
- tickLength: 0
- }
- });
- });
- /*---- placeholder4----*/
- $(function() {
- 'use strict'
- // We use an inline data source in the example, usually data would
- // be fetched from a server
- var data = [],
- totalPoints = 300;
- function getRandomData() {
- 'use strict'
- if (data.length > 0) data = data.slice(1);
- // Do a random walk
- while (data.length < totalPoints) {
- var prev = data.length > 0 ? data[data.length - 1] : 50,
- y = prev + Math.random() * 10 - 5;
- if (y < 0) {
- y = 0;
- } else if (y > 100) {
- y = 100;
- }
- data.push(y);
- }
- var res = [];
- for (var i = 0; i < data.length; ++i) {
- res.push([i, data[i]])
- }
- return res;
- }
- var updateInterval = 30;
- $("#updateInterval").val(updateInterval).change(function() {
- var v = $(this).val();
- if (v && !isNaN(+v)) {
- updateInterval = +v;
- if (updateInterval < 1) {
- updateInterval = 1;
- } else if (updateInterval > 2000) {
- updateInterval = 2000;
- }
- $(this).val("" + updateInterval);
- }
- });
- var plot = $.plot("#placeholder4", [getRandomData()], {
- series: {
- shadowSize: 0 // Drawing is faster without shadows
- },
- grid: {
- borderColor: "rgba(119, 119, 142, 0.1)",
- },
- colors: ["#6c5ffc"],
- yaxis: {
- min: 0,
- max: 100,
- tickLength: 0
- },
- xaxis: {
- tickLength: 0,
- show: false
- }
- });
- function update() {
- 'use strict'
- plot.setData([getRandomData()]);
- plot.draw();
- setTimeout(update, updateInterval);
- }
- update();
- });
- /*---- placeholder6----*/
- $(function() {
- 'use strict'
- var d1 = [];
- for (var i = 0; i <= 10; i += 1) {
- d1.push([i, parseInt(Math.random() * 30)]);
- }
- var d2 = [];
- for (var i = 0; i <= 10; i += 1) {
- d2.push([i, parseInt(Math.random() * 30)]);
- }
- var d3 = [];
- for (var i = 0; i <= 10; i += 1) {
- d3.push([i, parseInt(Math.random() * 30)]);
- }
- var stack = 0,
- bars = true,
- lines = false,
- steps = false;
- function plotWithOptions() {
- 'use strict'
- $.plot("#placeholder6", [d1, d2, d3], {
- series: {
- stack: stack,
- lines: {
- show: lines,
- fill: true,
- steps: steps
- },
- bars: {
- show: bars,
- barWidth: 0.6
- }
- },
- grid: {
- borderColor: "rgba(119, 119, 142, 0.1)",
- },
- colors: ['#6c5ffc', '#05c3fb'],
- yaxis: {
- tickLength: 0
- },
- xaxis: {
- tickLength: 0,
- show: false
- }
- });
- }
- plotWithOptions();
- $(".stackControls button").click(function(e) {
- e.preventDefault();
- stack = $(this).text() == "With stacking" ? true : null;
- plotWithOptions();
- });
- $(".graphControls button").click(function(e) {
- e.preventDefault();
- bars = $(this).text().indexOf("Bars") != -1;
- lines = $(this).text().indexOf("Lines") != -1;
- steps = $(this).text().indexOf("steps") != -1;
- plotWithOptions();
- });
- });
- $(function() {
- 'use strict'
-
- var data = [],
- series = Math.floor(Math.random() * 4) + 3;
- for (var i = 0; i < series; i++) {
- data[i] = {
- label: "Series" + (i + 1),
- data: Math.floor(Math.random() * 100) + 1
- }
- }
- var placeholder = $("#placeholder");
- $("#example-1").on('click', function() {
- placeholder.unbind();
- $("#title").text("Default pie chart");
- $("#description").text("The default pie chart with no options set.");
- $.plot(placeholder, data, {
- series: {
- pie: {
- show: true
- }
- },
- colors: ['#6c5ffc', '#05c3fb', '#09ad95', '#1170e4', '#f82649'],
- });
- });
- $("#example-2").on('click', function() {
- placeholder.unbind();
- $("#title").text("Default without legend");
- $("#description").text("The default pie chart when the legend is disabled. Since the labels would normally be outside the container, the chart is resized to fit.");
- $.plot(placeholder, data, {
- series: {
- pie: {
- show: true
- }
- },
- colors: ['#6c5ffc', '#05c3fb', '#09ad95', '#1170e4', '#f82649'],
- legend: {
- show: false
- }
- });
- });
- $("#example-3").on('click', function() {
- placeholder.unbind();
- $("#title").text("Custom Label Formatter");
- $("#description").text("Added a semi-transparent background to the labels and a custom labelFormatter function.");
- $.plot(placeholder, data, {
- series: {
- pie: {
- show: true,
- radius: 1,
- label: {
- show: true,
- radius: 1,
- formatter: labelFormatter,
- background: {
- opacity: 0.8
- }
- }
- }
- },
- colors: ['#1170e4', '#d43f8d', '#45aaf2', '#ecb403', '#e86a91'],
- legend: {
- show: false
- }
- });
- });
- $("#example-4").on('click', function() {
- placeholder.unbind();
- $("#title").text("Label Radius");
- $("#description").text("Slightly more transparent label backgrounds and adjusted the radius values to place them within the pie.");
- $.plot(placeholder, data, {
- series: {
- pie: {
- show: true,
- radius: 1,
- label: {
- show: true,
- radius: 3 / 4,
- formatter: labelFormatter,
- background: {
- opacity: 0.5
- }
- }
- }
- },
- colors: ['#1170e4', '#d43f8d', '#45aaf2', '#ecb403', '#64E572'],
- legend: {
- show: false
- }
- });
- });
- $("#example-5").on('click', function() {
- placeholder.unbind();
- $("#title").text("Label Styles #1");
- $("#description").text("Semi-transparent, black-colored label background.");
- $.plot(placeholder, data, {
- series: {
- pie: {
- show: true,
- radius: 1,
- label: {
- show: true,
- radius: 3 / 4,
- formatter: labelFormatter,
- background: {
- opacity: 0.5,
- color: "#000"
- }
- }
- }
- },
- colors: ['#1170e4', '#d43f8d', '#45aaf2', '#ecb403', '#e86a91'],
- legend: {
- show: false
- }
- });
- });
- $("#example-6").on('click', function() {
- placeholder.unbind();
- $("#title").text("Label Styles #2");
- $("#description").text("Semi-transparent, black-colored label background placed at pie edge.");
- $.plot(placeholder, data, {
- series: {
- pie: {
- show: true,
- radius: 3 / 4,
- label: {
- show: true,
- radius: 3 / 4,
- formatter: labelFormatter,
- background: {
- opacity: 0.5,
- color: "#000"
- }
- }
- }
- },
- colors: ['#1170e4', '#d43f8d', '#45aaf2', '#ecb403', '#e86a91'],
- legend: {
- show: false
- }
- });
- });
- $("#example-7").on('click', function() {
- placeholder.unbind();
- $("#title").text("Hidden Labels");
- $("#description").text("Labels can be hidden if the slice is less than a given percentage of the pie (10% in this case).");
- $.plot(placeholder, data, {
- series: {
- pie: {
- show: true,
- radius: 1,
- label: {
- show: true,
- radius: 2 / 3,
- formatter: labelFormatter,
- threshold: 0.1
- }
- }
- },
- colors: ['#1170e4', '#d43f8d', '#45aaf2', '#ecb403', '#e86a91'],
- legend: {
- show: false
- }
- });
- });
- $("#example-8").on('click', function() {
- placeholder.unbind();
- $("#title").text("Combined Slice");
- $("#description").text("Multiple slices less than a given percentage (5% in this case) of the pie can be combined into a single, larger slice.");
- $.plot(placeholder, data, {
- series: {
- pie: {
- show: true,
- combine: {
- color: "#999",
- threshold: 0.05
- }
- }
- },
- colors: ['#1170e4', '#d43f8d', '#45aaf2', '#ecb403', '#e86a91'],
- legend: {
- show: false
- }
- });
- });
- $("#example-9").on('click', function() {
- placeholder.unbind();
- $("#title").text("Rectangular Pie");
- $("#description").text("The radius can also be set to a specific size (even larger than the container itself).");
- $.plot(placeholder, data, {
- series: {
- pie: {
- show: true,
- radius: 500,
- label: {
- show: true,
- formatter: labelFormatter,
- threshold: 0.1
- }
- }
- },
- colors: ['#1170e4', '#d43f8d', '#45aaf2', '#ecb403', '#e86a91'],
- legend: {
- show: false
- }
- });
- });
- $("#example-10").on('click', function() {
- placeholder.unbind();
- $("#title").text("Tilted Pie");
- $("#description").text("The pie can be tilted at an angle.");
- $.plot(placeholder, data, {
- series: {
- pie: {
- show: true,
- radius: 1,
- tilt: 0.5,
- label: {
- show: true,
- radius: 1,
- formatter: labelFormatter,
- background: {
- opacity: 0.8
- }
- },
- combine: {
- color: "#999",
- threshold: 0.1
- }
- }
- },
- colors: ['#1170e4', '#d43f8d', '#45aaf2', '#ecb403', '#e86a91'],
- legend: {
- show: false
- }
- });
- });
- $("#example-11").on('click', function() {
- placeholder.unbind();
- $("#title").text("Donut Hole");
- $("#description").text("A donut hole can be added.");
- $.plot(placeholder, data, {
- series: {
- pie: {
- innerRadius: 0.5,
- show: true
- }
- }
- });
- });
- $("#example-1").click();
- });
- // A custom label formatter used by several of the plots
- function labelFormatter(label, series) {
- 'use strict'
- return "<div style='font-size:8pt; text-align:center; padding:2px; color:white;'>" + label + "<br/>" + Math.round(series.percent) + "%</div>";
- }
- //
- function setCode(lines) {
- 'use strict'
- $("#code").text(lines.join("\n"));
- }
|