- Local data
- Remote data
- Binding data using ODataAdaptor
- Empty points
Contact Support
Working with data in EJ2 JavaScript 3D Chart control
10 Jan 202416 minutes to read
Local data
A simple JSON data can be bound to the 3D chart using dataSource
property in series. Now map the fields in JSON to xName
and yName
properties.
var chartData = [
{ month: 'Jan', sales: 35 }, { month: 'Feb', sales: 28 },
{ month: 'Mar', sales: 34 }, { month: 'Apr', sales: 32 },
{ month: 'May', sales: 40 }, { month: 'Jun', sales: 32 },
{ month: 'Jul', sales: 35 }, { month: 'Aug', sales: 55 },
{ month: 'Sep', sales: 38 }, { month: 'Oct', sales: 30 },
{ month: 'Nov', sales: 25 }, { month: 'Dec', sales: 32 }
];
var chart3D = new ej.charts.Chart3D({
primaryXAxis: {
valueType: 'Category',
labelRotation: -45,
labelPlacement: 'BetweenTicks'
},
series:[{
dataSource: chartData,
type: 'Column',
xName: 'month',
yName: 'sales'
}],
wallColor: 'transparent',
enableRotation: true,
rotation: 7,
tilt: 10,
depth: 100,
}, '#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Remote data
The remote data can be bound to the 3D chart using the DataManager
. The DataManager
requires minimal information like web service URL, adaptor and cross domain to interact with service endpoint properly. Assign the instance of the DataManager
to the dataSource
property in series and map the fields of data to xName
and yName
properties. You can also use the query
property of the series to filter the data.
var dataManager = new ej.data.DataManager({
url: 'https://services.syncfusion.com/js/production/api/orders'
});
var query = new ej.data.Query().take(5).where('Estimate', 'lessThan', 3, false);
var chart3D = new ej.charts.Chart3D({
primaryXAxis: {
valueType: 'Category',
labelRotation: -45,
labelPlacement: 'BetweenTicks'
},
series:[{
dataSource: dataManager,
type: 'Column',
xName: 'CustomerID', yName: 'Freight', query: query
}],
wallColor: 'transparent',
enableRotation: true,
rotation: 7,
tilt: 10,
depth: 100,
}, '#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Binding data using ODataAdaptor
OData
is a standardized protocol for creating and consuming data. You can retrieve data from OData service using the DataManager
. Refer to the following code example for remote data binding using OData service.
var query = new ej.data.Query();
var data = new ej.data.DataManager({
url: 'https://services.syncfusion.com/js/production/api/orders',
adaptor: new ej.data.ODataAdaptor()
});
var chart3D = new ej.charts.Chart3D({
primaryXAxis: {
valueType: 'Category',
labelRotation: -45,
labelPlacement: 'BetweenTicks'
},
series:[{
dataSource: dataManager,
type: 'Column',
xName: 'CustomerID', yName: 'Freight', query: query,
}],
wallColor: 'transparent',
enableRotation: true,
rotation: 7,
tilt: 10,
depth: 100,
}, '#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Empty points
The data points that uses the null
or undefined
as value are considered as empty points. The empty data points are ignored and is not plotted in the chart. When the data is provided by using the points property, by using emptyPointSettings
property in series, the empty can be customized. The default mode
of the empty point is Gap.
var chartData = [
{ month: 'Jan', sales: 35 }, { month: 'Feb', sales: 28 },
{ month: 'Mar', sales: null }, { month: 'Apr', sales: 32 },
{ month: 'May', sales: 40 }, { month: 'Jun', sales: 32 },
{ month: 'Jul', sales: 35 }, { month: 'Aug', sales: undefined },
{ month: 'Sep', sales: 38 }, { month: 'Oct', sales: 30 },
{ month: 'Nov', sales: 25 }, { month: 'Dec', sales: 32 }
];
var chart3D = new ej.charts.Chart3D({
primaryXAxis: {
valueType: 'Category',
labelRotation: -45,
labelPlacement: 'BetweenTicks'
},
series:[{
dataSource: chartData,
xName: 'month',
yName: 'sales',
type: 'Column',
emptyPointSettings: {
mode: 'Gap'
}
}],
wallColor: 'transparent',
enableRotation: true,
rotation: 7,
tilt: 10,
depth: 100,
}, '#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Customizing empty point
The specific color for empty point can be set by the fill
property in emptyPointSettings
.
var chartData = [
{ month: 'Jan', sales: 35 }, { month: 'Feb', sales: 28 },
{ month: 'Mar', sales: null }, { month: 'Apr', sales: 32 },
{ month: 'May', sales: 40 }, { month: 'Jun', sales: 32 },
{ month: 'Jul', sales: 35 }, { month: 'Aug', sales: undefined },
{ month: 'Sep', sales: 38 }, { month: 'Oct', sales: 30 },
{ month: 'Nov', sales: 25 }, { month: 'Dec', sales: 32 }
];
var chart3D = new ej.charts.Chart3D({
primaryXAxis: {
valueType: 'Category',
labelRotation: -45,
labelPlacement: 'BetweenTicks'
},
series:[{
dataSource: chartData,
xName: 'month',
yName: 'sales',
type: 'Column',
emptyPointSettings: {
mode: 'Average',
fill: 'green'
}
}],
wallColor: 'transparent',
enableRotation: true,
rotation: 7,
tilt: 10,
depth: 100,
}, '#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/29.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>