Skip to content

Instantly share code, notes, and snippets.

@tripp
tripp / removeSeriesByKey.js
Last active December 19, 2015 00:49
Method accepts a chart reference and key of the series to be removed.
var removeSeriesByKey = function(chart, keyToDelete) {
var newDataProvider = [],
oldDataProvider = chart.get("dataProvider"),
oldItem,
newItem,
key,
i,
newSeriesStyles = {},
seriesCollection = chart.get("seriesCollection"),
seriesMap = chart.get("graph").get("seriesDictionary");
@tripp
tripp / getNewDataProvider.js
Created June 24, 2013 21:42
Merges and sorts to dataProvider arrays by date. (assumes the date value is associated with a value key of "date")
var getNewDataProvider = function(olddata, newdata) {
var firstArray,
secondArray,
firstLength,
newDataProvider = [],
firstDate,
secondDate,
firstItem,
secondItem,
tempItem,
@tripp
tripp / charts-annotations.js
Created May 31, 2013 00:23
charts-annotations.js
YUI.add('charts-annotations', function (Y) {
/**
* Allows for the creation of annotations for a chart.
*
* @module charts-annotations
*/
/**
* Creates a marker that can be used as an annotation.
*
* @class AnnotationMarker
@tripp
tripp / dsthack.js
Created March 15, 2013 02:21
Hacks the hour difference for a date range that straddles dst.
function normalizeForDST(dataProvider, key) {
var dateKey = key || "date",
len = dataProvider.length,
dsd = new Date("3/11/2013").valueOf(),
min = new Date(dataProvider[0][dateKey]).valueOf(),
max = new Date(dataProvider[len - 1][dateKey]).valueOf(),
multiplier = (1000 * 60 * 60)/(len - 1),
i,
day;
@tripp
tripp / styledlegend.js
Created March 1, 2013 19:19
Styling chart with legend using the series collection.
mychart = new Y.Chart({
dataProvider:myDataValues,
legend: {
position: "right"
},
seriesCollection: [
{
yKey: "successes",
styles: {
marker: {
@tripp
tripp / chainingexample.js
Created February 19, 2013 18:25
Chaining Example
YUI({
filter:"raw"
}).use('graphics', function (Y)
{
var w = 300,
h = 200,
ew = 15,
eh = 15,
mygraphic = new Y.Graphic({
render: "#mygraphiccontainer"
@tripp
tripp / MyWidgetContentBoxGetterOverride.js
Created February 14, 2013 22:28
MyWidgetContentBoxGetterOverride
function MockNode() {}
MockNode.prototype = {
getDOMNode: function() {
return this;
},
append: function(val) {
if(!this._children) {
this._children = [];
}
@tripp
tripp / StackedColumnRoundingMethodNull.js
Created February 12, 2013 16:59
A column chart with it's NumericAxis' roundingMethod attribute set to null.
YUI().use('charts', function (Y)
{
var myDataValues = [
{category:"5/1/2010", miscellaneous:2000, expenses:3700, revenue:2200},
{category:"5/2/2010", miscellaneous:50, expenses:9100, revenue:100},
{category:"5/3/2010", miscellaneous:400, expenses:1100, revenue:1500},
{category:"5/4/2010", miscellaneous:200, expenses:1900, revenue:2800},
{category:"5/5/2010", miscellaneous:5000, expenses:5000, revenue:2650}
],
mychart = new Y.Chart({
@tripp
tripp / gist:4680116
Created January 31, 2013 04:18
changedatatwonumericaxeschart.js
var myDataValues = [
{Iter:1, Generation:0, fitness:1.0542625639857393},
{Iter:1, Generation:1, fitness:0.4268963274830605},
{Iter:1, Generation:34, fitness:0.36754170974222156},
{Iter:2, Generation:0, fitness:1.483161509937983},
{Iter:2, Generation:1, fitness:0.20846076233482433},
{Iter:3, Generation:0, fitness:0.42917710631074113},
{Iter:3, Generation:19, fitness:0.3964440041134349},
{Iter:3, Generation:20, fitness:0.15911543465202604},
{Iter:3, Generation:94, fitness:0.12314257358831804},
@tripp
tripp / colorcodedtooltip.js
Created October 1, 2012 21:38
colorcodedtooltip.js
var myTooltip = {
planarLabelFunction: function(categoryAxis, valueItems, index, seriesArray, seriesIndex)
{
var doc = Y.config.doc,
msg = doc.createElement("div"),
valueItem,
i = 0,
len = seriesArray.length,
axis,
categoryValue,