Remove the option to enable hidden graph(X button ) in Amchart - javascript

I'm trying to enable and disable a graph from my code. I don't want the user to enable the hidden graphs from the UI using the cross button displayed against the hidden graphs in Amchart. How to remove the cross button when the graph is hidden from code ?
For the sake of demo I have hidden the graph on render to display the cross button.
Here is a DEMO.
Here is the code:
var chartData1 = [];
var chartData2 = [];
generateChartData();
function generateChartData() {
var firstDate = new Date();
firstDate.setDate(firstDate.getDate() - 500);
firstDate.setHours(0, 0, 0, 0);
for (var i = 0; i < 500; i++) {
var newDate = new Date(firstDate);
newDate.setDate(newDate.getDate() + i);
var a1 = Math.round(Math.random() * (40 + i)) + 100 + i;
var a2 = -1 * Math.round(Math.random() * (100 + i)) + 200 + i;
chartData1.push({
date: newDate,
value: a1
});
chartData2.push({
date: newDate,
value: a2
});
}
}
AmCharts.makeChart("chartdiv", {
type: "stock",
listeners: [{
event: "rendered",
method: hide
}],
dataSets: [{
title: "first data set",
fieldMappings: [{
fromField: "value",
toField: "value"
}],
dataProvider: chartData1,
categoryField: "date"
},
{
title: "second data set",
fieldMappings: [{
fromField: "value",
toField: "value2"
}],
dataProvider: chartData2,
categoryField: "date",
compared: true
}
],
panels: [{
showCategoryAxis: false,
title: "Data set #1",
recalculateToPercents: "never",
stockGraphs: [{
id: "g1",
valueField: "value",
comparable: true
}],
stockLegend: {
}
}, {
showCategoryAxis: true,
title: "Data set #2",
recalculateToPercents: "never",
stockGraphs: [{
id: "g2",
valueField: "value2",
compareField: "value2",
comparable: true,
visibleInLegend: false
}],
stockLegend: {
}
}
],
chartScrollbarSettings: {
graph: "g1"
},
chartCursorSettings: {
valueBalloonsEnabled: true,
fullWidth:true,
cursorAlpha:0.1
},
periodSelector: {
periods: [{
period: "MM",
selected: true,
count: 1,
label: "1 month"
}, {
period: "YYYY",
count: 1,
label: "1 year"
}, {
period: "YTD",
label: "YTD"
}, {
period: "MAX",
label: "MAX"
}]
}
});
function hide(chart){
chart.chart.panels[0].graphs[0].hidden = true;
}

Set visibleInLegend and compareGraphVisibleInLegend to false in the stock graph object you want to hide. The former works on the main dataset while the latter works on a compared dataset (Dataset 2 in your case).
stockGraphs: [{
id: "g1",
valueField: "value",
comparable: true,
visibleInLegend: false,
compareGraphVisibleInLegend: false //takes affect when dataset 1 becomes a compared dataset rather than the main one
}],
Updated codepen

Related

Display Kendo Chart (pie chart) based on grid data

I am using KendoUI - Grid component
How can I convert this into Kendo Grid:
For Eg:
I have created kendo grid (table) by using local data. As soon as I click on "Generate chart" button, above table's filter data should create the Kendo pie chart like below...
As I am new to Kendo, can somebody please suggest me the answer?
Code:
var localData = [
{
Id: 1,
userName: "John",
game: "A",
difficultyLevel: "Easy",
startTime: "25-05-2017",
endTime: "26-05-2017",
score: "210"
},
{
Id: 2,
userName: "Sam",
game: "B",
difficultyLevel: "Hard",
startTime: "04-11-2016",
endTime: "01-12-2016",
score: "4800"
},
];
var dataSource = new kendo.data.DataSource({
data: localData,
schema: {
model: {
fields: {
Id: {
type: "number"
},
userName: {
type: "string"
},
userName: {
type: "string"
},
difficultyLevel: {
type: "string"
},
startTime: {
type: "string"
},
endTime: {
type: "string"
},
score: {
type: "number"
},
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
rowTemplate: $.proxy(kendo.template($("#rowTemplate").html()), dataSource),
scrollable: true,
height: 300,
sortable: true,
filterable: false,
groupable: true,
pageable: true,
columns: [{
field: "Id",
title: "Id",
filterable: true
}, {
field: "userName",
title: "userName"
}, {
field: "game",
title: "game"
}, {
field: "difficultyLevel",
title: "difficultyLevel"
}, {
field: "startTime",
title: "startTime"
}, {
field: "endTime",
title: "endTime"
}, {
field: "score",
title: "score"
}]
});
JsFiddle
You need to prepare your data to the chart's format. Something like:
$chartContainer.kendoChart({
dataSource: {
data: localData,
schema: {
parse: function(data) {
return data.map(x => {
return {
value: Number(x.score),
category: x.userName
}
});
}
}
},
series: [{
type: "pie",
field: "value",
categoryField: "category"
}],
tooltip: {
visible: true,
template: "#= category #: #= value #"
}
});
Updated Fiddle

How can I get the row value when edit any text in row of scrolling table in Gojs?

I'm working with scrolling table in Gojs.
I've set the property "editable: true" for my table. Now, suppose I've edited a text in any column of a row, then how can I get the data for this entire row or edited text?
Please let me know if you know this.
Here is my code:
var nodeJson;
var $ = go.GraphObject.make;
var inputFieldTable = [
{ ID: "001", Name: "Input 1", Text: "Err1" },
{ ID: "002", Name: "Input 2", Text: "Err2" },
{ ID: "003", Name: "Input 3", Text: "Err3" },
{ ID: "004", Name: "Input 4", Text: "Err4" }
];
var outputFieldTable = [
{ ID: "101", Name: "Output 1", Text: "Integer" },
{ ID: "102", Name: "Output 2", Text: "Integer" },
{ ID: "103", Name: "Output 3", Text: "Integer" },
{ ID: "104", Name: "Output 4", Text: "String" },
{ ID: "105", Name: "Output 5", Text: "String" },
{ ID: "106", Name: "Output 6", Text: "Double" }
];
myDiagram =
$(go.Diagram, "myDiagramDiv",
{
initialContentAlignment: go.Spot.Center,
"undoManager.isEnabled": true,
allowMove: false,
allowDelete: true,
allowCopy: false,
allowDragOut: false,
allowDrop: false
});
myDiagram.nodeTemplate =
$(go.Node, "Vertical",
{
selectionObjectName: "SCROLLING",
resizable: false, resizeObjectName: "SCROLLING",
portSpreading: go.Node.SpreadingNone
},
new go.Binding("location").makeTwoWay(),
$(go.TextBlock,
{ font: "bold 14px sans-serif" },
new go.Binding("text", "key")),
$(go.Panel, "Auto",
$(go.Shape, { fill: "white" }),
$("ScrollingTable",
{ stretch: go.GraphObject.Fill },
new go.Binding("TABLE.itemArray", "items"),
new go.Binding("TABLE.column", "left", function (left) { return left ? 2 : 0; }),
new go.Binding("desiredSize", "size").makeTwoWay(),
{
name: "SCROLLING",
desiredSize: new go.Size(100, 100),
"TABLE.itemTemplate":
$(go.Panel, "TableRow",
{
defaultStretch: go.GraphObject.Horizontal,
fromSpot: go.Spot.LeftRightSides,
toSpot: go.Spot.LeftRightSides,
fromLinkable: true,
toLinkable: true,
},
new go.Binding("portId", "Name"),
$(go.TextBlock, { column: 1 }, new go.Binding("text", "Name")),
$(go.TextBlock, { column: 2 }, new go.Binding("text", "Text"), { editable: true })
),
"TABLE.defaultColumnSeparatorStroke": "gray",
"TABLE.defaultColumnSeparatorStrokeWidth": 0.5,
"TABLE.defaultRowSeparatorStroke": "gray",
"TABLE.defaultRowSeparatorStrokeWidth": 0.5,
"TABLE.defaultSeparatorPadding": new go.Margin(1, 3, 0, 3)
}
)
)
);
myDiagram.model = $(go.GraphLinksModel,
{
linkFromPortIdProperty: "fromPort",
linkToPortIdProperty: "toPort",
nodeDataArray: [
{
key: "Input", left: true, location: new go.Point(0, 0), size: new go.Size(170, 100),
items: inputFieldTable
},
{
key: "Output", location: new go.Point(300, 0), size: new go.Size(170, 100),
items: outputFieldTable, editable: true
}
]
});
//Function to handle editing of Scrolling Tables row data
myDiagram.addDiagramListener("TextEdited",
function (e) {
// alert("Text is changed.");
var part = e.subject.part;
if (part.data.key.toUpperCase() == "INPUT") {
myDiagram.rollbackTransaction();
return false;
}
else if (part.data.key.toUpperCase() == "OUTPUT") {
if ((part instanceof go.Node)) {
//NEED TO KNOW THE ENTIRE ROW DATA HERE
}
}
});
Are you asking about how to get to the item data from within your "TextEdited" listener?
e.subject will be the edited TextBlock.
e.subject.panel will be the containing Panel, which is a "TableRow" in your Panel.itemTemplate.
e.subject.panel.data will be the item data -- i.e. the data for that row.
This applies to all Panels with itemArrays -- not just in a "ScrollingTable".
It's a little odd for a TextBlock.editable TextBlock not to have a TwoWay Binding, but it can be OK depending on what you do in your "TextEdited" listener.
you'll have to get all the values from the model by calling the below
myDiagram.model.nodeDataArray
you'll then need to iterate through the objects to determine what values have changed.

SAPUI5 VIZ column chart integration. Invalid databinding error

I am trying to show VIZ chart from SAPUI5 but unable to bind data received from model. It throws [50017] - Invalid data binding error. I am posting my code below please have a look at it and help me find the causs.
var assignedContentData = {
"AssignedContentData": [{
"description": "Capital",
"newsletter": 2,
"press_release": 12,
"letter": 1,
"notice": 0,
"bulletin_memorandum": 0
}, {
"description": "NA",
"newsletter": 0,
"press_release": 0,
"letter": 0,
"notice": 1,
"bulletin_memorandum": 0
}, {
"description": "Equity",
"newsletter": 0,
"press_release": 4,
"letter": 0,
"notice": 5,
"bulletin_memorandum": 12
}]
};
var oAssignContentModel = new sap.ui.model.json.JSONModel({
data: assignedContentData
});
sap.ui.getCore().setModel(oAssignContentModel, "oAssignContentModel");
var assignedContentBarChart = new sap.viz.ui5.controls.VizFrame("assignedContentBarChart", {
vizType: "stacked_column"
});
var oDatasetAssignedContentBar = new sap.viz.ui5.data.FlattenedDataset({
dimensions: [{
name: "Description",
value: "{description}"
}],
measures: [{
name: "Newsletter",
value: "{newsletter}"
}],
data: {
path: "/data/AssignedContentData"
}
});
var feedValueAxis1 = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "valueAxis",
'type': "Measure",
'values': ["Newsletter"]
});
var feedCategoryAxis1 = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "categoryAxis",
'type': "Dimension",
'values': ["Description"]
});
var feedColorAxis1 = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "color",
'type': "Dimension",
'values': ["Newsletter", "Press_Release", "Letter", "Notice", "Bulletin_memorandum"]
});
assignedContentBarChart.setVizProperties({
plotArea: {
dataLabel: {
visible: true,
formatString: "#,##0"
}
},
legend: {
title: {
visible: false
}
},
title: {
visible: true,
text: 'Bar Chart'
}
});
assignedContentBarChart.setDataset(oDatasetAssignedContentBar);
assignedContentBarChart.addFeed(feedValueAxis1);
assignedContentBarChart.addFeed(feedCategoryAxis1);
Your binding is incorrect. As your model name is oAssignContentModel, it must be reflected in the binding as well in the data property assignment:
var oDatasetAssignedContentBar = new sap.viz.ui5.data.FlattenedDataset({
dimensions: [{
name: "Description",
value: "{description}"
}],
measures: [{
name: "Newsletter",
value: "{newsletter}"
}],
data: {
path: "oAssignContentModel>/data/AssignedContentData"
}
});
Or you can remove the name from the model, and you can leave the data binding as it is now:
sap.ui.getCore().setModel(oAssignContentModel);

KendoUI Bar Chart categoryAxis grouping issue

I am facing issue with categoryAxis when any one item is missing in the grouping. I have modified the code in below fiddle
http://jsfiddle.net/v8tsQ/9/
I have replaced the javascript as below:-
var dr =
[{
"currency":"AUD",
"paymenttype":"0",
"amount":"10"
},
{
"currency":"AUD",
"paymenttype":"3",
"amount":"11"
},
{
"currency":"CAD",
"paymenttype":"1",
"amount":"24"
},
{
"currency":"CAD",
"paymenttype":"0",
"amount":"23"
},
{
"currency":"CAD",
"paymenttype":"3",
"amount":"22"
}]
var ds = new kendo.data.DataSource({
data: dr,
group: {
field: "paymenttype"
},
sort: [{
field: "paymenttype",
dir: "asc"
}, {
field: "currency",
dir: "asc"
}]
})
$("#chart").kendoChart({
dataSource: ds,
seriesDefaults: {
type: 'column',
labels: {
visible: true,
template: "#=kendo.format('{0:0}', value)#"
}
},
legend: {
visible: true,
position: "bottom"
},
series: [{
field: "amount"
}],
categoryAxis: {
field: "currency"
},
tooltip: {
visible: true,
template: "#= dataItem.currency#"
}
});
Issue :
The CAD currency is showing under AUD for type 1, which does not exists for currency AUD.
Please suggest.
Thanks

Split JSON into Multiple Array Series Highcharts

i get my JSON object from my php code in this format (JSONlint ok) :
[
[1375653600000,3.20104,175.00,116.00,11.00,31.00],[...],[1376776800000,2.85625,10.00,1.00,0.00,8.00]
]
i Have to split in 5 different series:
[1375653600000, 3.201014]
[1375653600000, 175.00]
[1375653600000, 116.00]
[1375653600000, 11.00]
[1375653600000, 31.00]
...
and (obviously) each array is for a different highcharts series.
i follow this post to get an idea about split the JSON:
Retrieving JSON data for Highcharts with multiple series?
This is my code:
$(function() {
// See source code from the JSONP handler at https://github.com/highslide-software/highcharts.com/blob/master/samples/data/from-sql.php
$.getJSON('grafico_nuovo.php?callback=?', function(data) {
// Add a null value for the end date
data = [].concat(data, [[Date.UTC(2012, 9, 14, 19, 59), null, null, null, null]]);
// create the chart
$('#container').highcharts('StockChart', {
chart : {
type: 'spline',
zoomType: 'xy'
},
navigator : {
adaptToUpdatedData: false,
series : {
data : data
}
},
scrollbar: {
liveRedraw: false
},
title: {
text: 'analisi consumi e temperature'
},
subtitle: {
text: 'Analisi test solo temperatura media'
},
rangeSelector : {
buttons: [{
type: 'hour',
count: 1,
text: '1h'
}, {
type: 'day',
count: 2,
text: '2d'
}, {
type: 'week',
count: 1,
text: '1w'
},{
type: 'month',
count: 1,
text: '1m'
}, {
type: 'year',
count: 1,
text: '1y'
}, {
type: 'all',
text: 'All'
}],
inputEnabled: true, // it supports only days
selected : 2 // day
},
/*xAxis : {
events : {
afterSetExtremes : afterSetExtremes
},
minRange: 3600 * 1000 // one hour
},*/
xAxis: {
events : {
afterSetExtremes : afterSetExtremes
},
minRange: 3600 * 1000, // one hour
type: 'datetime',
dateTimeLabelFormats: { minute: '%H:%M', day: '%A. %e/%m' },
// minRange: 15*60*1000,
//maxZoom: 48 * 3600 * 1000,
labels: {
rotation: 330,
y:20,
staggerLines: 1 }
},
yAxis: [{ // Primary yAxis
labels: {
format: '{value}°C',
style: {
color: '#89A54E'
}
},
title: {
text: 'Temperature',
style: {
color: '#89A54E'
}
}
}, { // Secondary yAxis
title: {
text: 'Consumo',
style: {
color: '#4572A7'
}
},
labels: {
format: '{value} Kw',
style: {
color: '#4572A7'
}
},
opposite: true
}],
series: [{
name: 'val1',
data: []
}, {
name: 'val2',
data: []
},
{
name: 'val3',
data: []
},
{
name: 'val4',
data: []
},
{
name: 'val5',
data: []
}]
});
});
});
/**
* Load new data depending on the selected min and max
*/
function afterSetExtremes(e) {
var currentExtremes = this.getExtremes(),
range = e.max - e.min,
chart = $('#container').highcharts();
chart.showLoading('Loading data from server...');
$.getJSON('grafico_nuovo.php?start='+ Math.round(e.min) +
'&end='+ Math.round(e.max) +'&callback=?', function(data) {
val1 = [];
val2 = [];
val3 = [];
val4 = [];
val5 = [];
$.each(data, function(key,value) {
val1.push([value[0], value[1]]);
val2.push([value[0], value[2]]);
val3.push([value[0], value[3]]);
val4.push([value[0], value[4]]);
val5.push([value[0], value[5]]);
});
console.log('val1');
chart.series[0].setData(val1);
chart.series[1].setData(val2);
chart.series[2].setData(val3);
chart.series[3].setData(val4);
chart.series[4].setData(val5);
chart.hideLoading();
});
}
The navigator works fine (with little trouble after 3-4 clicks) but the other series doesn't show.
Everything should be ok, but i've probably missed something

Categories

Resources