$(function(){
$("#pie").dxPieChart({
palette: paletteCollection[0],
dataSource: dataSource,
series: {},
legend: {
visible: false
},
onDrawn: function(e) {
var paletteName = e.component.option("palette"),
palette = DevExpress.viz.getPalette(paletteName).simpleSet,
paletteContainer = $(".palette-container");
paletteContainer.html("");
palette.forEach(function(color) {
$("<div>").css({
backgroundColor: color
})
.addClass("palette-item")
.appendTo(paletteContainer);
});
}
});
$("#palette").dxSelectBox({
items: paletteCollection,
value: paletteCollection[0],
onValueChanged: function(e) {
$("#pie").dxPieChart({
palette: e.value
});
}
});
$("#extension-mode").dxSelectBox({
items: paletteExtensionModes,
value: "Blend",
onValueChanged: function(e) {
$("#pie").dxPieChart({
paletteExtensionMode: e.value
});
}
});
});
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>DevExtreme Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script>
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/20.2.4/css/dx.common.css" />
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/20.2.4/css/dx.light.css" />
<script src="https://cdn3.devexpress.com/jslib/20.2.4/js/dx.all.js"></script>
<script src="data.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="index.js"></script>
</head>
<body class="dx-viewport">
<div class="demo-container">
<div class="flex-container">
<div id="pie" class="flex-block"></div>
<div class="palette-container flex-block"></div>
</div>
<div class="options">
<div class="caption">Options</div>
<div class="option">
<span>Palette</span>
<div id="palette"></div>
</div>
<div class="option">
<span>Palette Extension Mode</span>
<div id="extension-mode"></div>
</div>
</div>
</div>
</body>
</html>
.flex-container{
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
#pie {
height: 350px;
width: 500px;
margin: 20px;
}
.palette-container{
float: left;
}
.palette-item{
width: 40px;
height: 40px;
}
.options {
padding: 20px;
background-color: rgba(191, 191, 191, 0.15);
margin-top: 20px;
}
.caption {
font-size: 18px;
font-weight: 500;
}
.option {
display: inline-block;
min-width: 320px;
margin-top: 5px;
}
.option > span {
margin: 0 10px 0 0;
}
.option > .dx-widget {
display: inline-block;
vertical-align: middle;
}
var paletteCollection = ["Material", "Soft Pastel", "Harmony Light", "Pastel", "Bright", "Soft", "Ocean", "Office", "Vintage", "Violet", "Carmine", "Dark Moon", "Soft Blue", "Dark Violet", "Green Mist"],
paletteExtensionModes = ["Alternate", "Blend", "Extrapolate"],
dataSource = [],
i;
for (i = 0; i < 20; i++) {
dataSource.push({
arg: "item" + i,
val: 1
});
}