let pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
width: "100%",
height: 500,
toolbar: true,
customizeChartElement: customizeChartElementFunction,
report: {
dataSource: {
filename: "data/data.csv"
},
slice: {
columns: [{
uniqueName: "Country"
},
{
uniqueName: "[Measures]"
}
],
measures: [{
uniqueName:"Price",
aggregation: "average"
}]
},
options: {
viewType: "charts",
chart: {
type: "column",
showLegend: false
}
}
}
});
function customizeChartElementFunction(element, data) {
let redColor = tinycolor("red");
let greenColor = tinycolor("green");
if (data.value > 6000) {
element.style.fill = applyShade(redColor, element.style.fill).toRgbString();
element.style.setProperty('opacity', '100%', 'important');
} else {
element.style.fill = applyShade(greenColor, element.style.fill).toRgbString();
element.style.setProperty('opacity', '100%', 'important');
}
}
function applyShade(newColor, oldColor) {
//Get the lightness of the default color
//Here we divide it by 2 to adjust the default lightness and get a darker color as a result
let colorLightness = tinycolor(oldColor).toHsl().l / 2;
//Apply the lightness to the new color
let result = newColor.toHsl();
result.l = colorLightness;
//Return the created color shade
return tinycolor(result);
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.