Highchart Android How to implement drilldown in loop - highcharts

My problem is in the drilldown. I want to create a drilldown on loop but all drilldown series show in one serie, the result is when I click on column, all drilldowns series show in that char.
ArrayList<Object> dataMinorAlarms = new ArrayList<>();
ArrayList<Object> dataMajorAlarms = new ArrayList<>();
ArrayList<Object> dataCriticalAlarms = new ArrayList<>();
ArrayList<Object> dataDrilldownlAlarms = new ArrayList<>();
ArrayList<Object> DrilldownlAlarms = new ArrayList<>();
for (ResumenGraph data:resumenGraphs){
HashMap<String, Object> minor = new HashMap<>();
minor.put("name", data.getName());
minor.put("y", data.getData().getMinor());
minor.put("drilldown", data.getName());
HashMap<String, Object> major = new HashMap<>();
major.put("name", data.getName());
major.put("y", data.getData().getMajor());
major.put("drilldown", data.getName());
HashMap<String, Object> critical = new HashMap<>();
critical.put("name", data.getName());
critical.put("y", data.getData().getCritical());
critical.put("drilldown", data.getName());
for (int i = 0; i < data.getDrilldown().size(); i++) {
HIColumn series4 = new HIColumn();
series4.setName(data.getName());
series4.setId(data.getName());
Object[] object2 = new Object[]{data.getDrilldown().get(i).getName(),data.getDrilldown().get(i).getData().getMajor()};
dataDrilldownlAlarms.add(object2);
DrilldownlAlarms.add(series4);
}
dataMinorAlarms.add(minor);
dataMajorAlarms.add(major);
dataCriticalAlarms.add(critical);
}

You need to use real x and y values from the Point class, there is not someting like index property.
You can find a similar example in the highcharts-android wrapper documentation.
API: https://api.highcharts.com/class-reference/Highcharts.Point#toc3
Docs: https://github.com/highcharts/highcharts-android/blob/master/README.md

Related

Cast json in to Map<String,Map<String,String>> Format

I need to convert the json string to nested Map and access the same.
Following Json String is in form of Map given below
Map<String,Map<String,String>>
{"0":{"1551874690005":"2","1551874722124":"2","1551874810817":"2","1551874681110":"2","1551874739821":"2","1551874763604":"2","1551874692381":"2","1551874816028":"2","1551874708292":"2","1551874804308":"2","1551874694205":"2","1551874696644":"2","1551874729332":"2","1551874749950":"2","1551874767786":"2"},"1":{"1551948649643":"0","1551948733576":"0","1551948601167":"0","1551948592816":"0","1551948699297":"0","1551874822043":"2","1551948681513":"0","1551948531568":"0","1551948577374":"0","1551948719758":"0","1552370125650":"0","1551948549863":"0","1551948564519":"0","1551948631000":"0","1551953956716":"0"},"2":{"1551875011432":"0","1551875020618":"0","1551874991952":"0","1551875091300":"0","1551875073622":"0","1551875032851":"0","1551874827691":"0","1551948658122":"0","1551874846523":"0","null":"0","1552545417127":"0","1551875083856":"0","1551874929076":"0","1552545972738":"0"},"3":{"1552651031695":"0"},"4":{"1551875144268":"0","1551875157028":"0","1551875115211":"0","1551875124660":"0"}}
Getting following error while trying using my code:
Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Map<String, String>' in type cast
Map offlineExeStatus = jsonDecode(prefs.getString("offlineExeStatus"));
Map<String,Map<String,String>> exeStatusFinalJson = new Map();
exeStatusFinalJson = offlineExeStatus.cast<String,Map<String,String>();
Need to cast the given json in "exeStatusFinalJson" Map and access like:
exeStatusFinalJson["0"] should give the output like:
{"1551874690005":"2","1551874722124":"2","1551874810817":"2","1551874681110":"2","1551874739821":"2","1551874763604":"2","1551874692381":"2","1551874816028":"2","1551874708292":"2","1551874804308":"2","1551874694205":"2","1551874696644":"2","1551874729332":"2","1551874749950":"2","1551874767786":"2"}
Try to declare your map as Map<String, dynamic> rather than Map<String, Map<String, String>>.
Finally figured out the way to do it!
Map offlineExeStatus = jsonDecode(prefs.getString("onlineExeStatus"));
Map<String, dynamic> exeStatusJson = new Map();
Map<String, Map<String, String>> exeStatusFinalJson = new Map();
List<String> mapKeyExe = new List();
mapKeyExe = offlineExeStatus.keys.cast<String>().toList();
exeStatusJson = offlineExeStatus.cast<String, dynamic>();
for (int i = 0; i < mapKeyExe.length; i++) {
Map<String, String> exeStatusInsideJson = new Map();
exeStatusInsideJson = offlineExeStatus[mapKeyExe[i].toString()]
.cast<String, String>();
exeStatusFinalJson[i.toString()] = exeStatusInsideJson;
print(exeStatusFinalJson);
}

Animate Random Movement of vertex on jung

I created graph with static Layout in Jung. I have a method for random movement on 2D which moves the vertex for some number of steps. I appreciate the power of JUNG in most of the operations in my project but I wanted to animate the movement of the vertex when random walk method is called. I need help with this regard. below is my graph code.
final int NUM_WALKS = 41;
int count = 0;
while (count < NUM_WALKS) {
sa.randomwalk();
Graph<Integer, String> gr = wsn.generateRandomGraph();
Transformer<Integer, Point2D> locationTransformer = new Transformer<Integer, Point2D>() {
#Override
public Point2D transform(Integer vertex) {
int value = (vertex.intValue());// * 40) + 20;
Map<Integer, Integer> MapX = new HashMap<Integer, Integer>();
MapX = WirelesSensorNetwork.MapX_Object();
Map<Integer, Integer> MapY = new HashMap<Integer, Integer>();
MapY = WirelesSensorNetwork.MapY_Object();
return new Point2D.Float(MapX.get(value), MapY.get(value));
}
};
Dimension preferredSize = new Dimension(700, 600);
StaticLayout<Integer, String> layout = new StaticLayout<Integer, String>(gr, locationTransformer);
layout.setSize(new Dimension(300, 250));
VisualizationViewer<Integer, String> vv = new VisualizationViewer<Integer, String>(layout,
preferredSize);
vv.setBackground(Color.WHITE);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<Integer, String>());
JFrame frame = new JFrame("Wireless Sensor Network ");
frame.getContentPane().setBackground(Color.WHITE);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
count++;
}
There's a lot I don't know about your program, so I can't actually test this.
You may find it useful to start with something like this:
// set up variables (you must be declaring 'sa' somewhere up here....)
final int NUM_WALKS = 41;
int count = 0;
// do first randomwalk
sa.randomwalk();
// create the graph, layout, and visualization
Graph<Integer, String> gr = wsn.generateRandomGraph();
// get locations for first layout
Transformer<Integer, Point2D> locationTransformer = new Transformer<Integer, Point2D>() {
#Override
public Point2D transform(Integer vertex) {
int value = (vertex.intValue());// * 40) + 20;
Map<Integer, Integer> MapX = new HashMap<Integer, Integer>();
MapX = WirelesSensorNetwork.MapX_Object();
Map<Integer, Integer> MapY = new HashMap<Integer, Integer>();
MapY = WirelesSensorNetwork.MapY_Object();
return new Point2D.Float(MapX.get(value), MapY.get(value));
}
};
// create the first StaticLayout
StaticLayout<Integer, String> layout = new StaticLayout<Integer, String>(gr, locationTransformer);
layout.setSize(new Dimension(300, 250));
// create the visualization
Dimension preferredSize = new Dimension(700, 600);
VisualizationViewer<Integer, String> vv = new VisualizationViewer<Integer, String>(layout,
preferredSize);
vv.setBackground(Color.WHITE);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<Integer, String>());
JFrame frame = new JFrame("Wireless Sensor Network ");
frame.getContentPane().setBackground(Color.WHITE);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
// increment the count, since we have run the randomwalk one time
count++;
// do the rest of the randomwalks
// you might need to do something to slow down this loop so that it does not
// go too fast for the visualization to keep up with.
while (count < NUM_WALKS) {
sa.randomwalk();
// make a new location transformer after each walk
Transformer<Integer, Point2D> nextLocationTransformer = new Transformer<Integer, Point2D>() {
#Override
public Point2D transform(Integer vertex) {
int value = (vertex.intValue());// * 40) + 20;
Map<Integer, Integer> MapX = new HashMap<Integer, Integer>();
MapX = WirelesSensorNetwork.MapX_Object();
Map<Integer, Integer> MapY = new HashMap<Integer, Integer>();
MapY = WirelesSensorNetwork.MapY_Object();
return new Point2D.Float(MapX.get(value), MapY.get(value));
}
};
// make a new layout with the new location transformer
StaticLayout<Integer, String> newLayout = new StaticLayout<Integer, String>(gr, nextLocationTransformer);
newLayout.setSize(new Dimension(300, 250));
// animate the existing visualization to move from the previous layout to the new one
LayoutTransition<Integer, String> lt =
new LayoutTransition<Integer, String>(vv, vv.getGraphLayout(),
newLayout);
Animator animator = new Animator(lt);
animator.start();
count++;
}

How to set the value in hashmap key:value pair conditionally?

I'am using grails.
I want to set the values in map conditionally.
For Eg:
HashMap<String, String> mymap= new HashMap<String, String>();
if (author != null){
mymap['TITLE'] = book.title
}else{
mymap['TITLE'] = 'NA'
}
So, what I want to acheive is, I want to set the value of my title as "book.title" if the particular value is not null otherwise it should be a normal string "NA".
Output I'am Getting
mymap:[TITLE: NA]
Output I want
mymap:[TITLE: [TITLE1, TITLE2, NA, TITLE4, TITLE5]]
Something like this
Thanks in advance.
You are using groovy all of this can be done more elegantly:
You must be getting iteration of book from somewhere ?
Change this from:
HashMap<String, String> mymap= new HashMap<String, String>();
if (author != null){
mymap['TITLE'] = book.title
}else{
mymap['TITLE'] = 'NA'
}
to:
List titles=[]
books?.title?.each { title->
titles<< (title?:'NA')
}
def mymap=['TITLE':titles]
Use this instead :
HashMap<String, List<String>> map = new HashMap<String, List<String>>();
List<String> myList = new ArrayList<String>();
if (author != null){
myList.add(book.title)
}else{
myList.add('NA')
}
map.put("TITLE",myList) ;
Shorter variant:
HashMap<String, List<String>> map = [:].withDefault{ [] }
map[ 'TITLE' ] << ( author ? book.title : 'NA' )

Not Displaying Data

Can any one please help me for this.
public Dictionary<string,object> UserExistOrNot()
{
Dictionary<string, object> result = new Dictionary<string, object>();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
string _userName = "user01";
string _password = "user";
string sqlQuery = "select * from [User] t0 inner join UserProfile t1 on t0.UserId=t1.UserId where t0.UserName='" + _userName + "' and t0.Password='" + _password+"'";
SqlDataAdapter da = new SqlDataAdapter(sqlQuery, con);
DataSet ds = new DataSet();
da.Fill(ds, "usertable");
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
result.Add("UserId", dr["UserId"]);
result.Add("UserName", dr["UserName"]);
result.Add("Password", dr["Password"]);
result.Add("Email", dr["Email"]);
result.Add("Mobile", dr["Mobile"]);
result.Add("Gender", dr["Gender"]);
result.Add("Street1", dr["Street1"]);
result.Add("Street2", dr["Street2"]);
result.Add("Street3", dr["Street3"]);
result.Add("Street4", dr["Street4"]);
result.Add("CityId", dr["CityId"]);
result.Add("StateId", dr["StateId"]);
result.Add("Country", dr["Country"]);
}
}
else
return result;
return result;
}
Output displaying like this:
System.Collections.Generic.Dictionary`2[System.String,System.Object]
I want to display the data instead of type
Browser understands pure text, xml or html, but not complex types, so you have to return one of those types, or create a view with model Dictionary and iterate throw keys and vslues to see it.

Insert data in TableModel.addRow into Blackberry TableView

I need to Create a table where 3 columns are needed and can have multiple rows. I am using BlackBerry API version 6. I have debugged my code and it's giving IllegalArgumentException. I am not able to sort this error out.
My code is as follows:
public class designTableLayout extends MainScreen{
TableModel theModel = new TableModel();
theView = new TableView(theModel);
TableController theController = new TableController(theModel, theView,
TableController.FIELD_FOCUS);
theView.setController(theController);
HeaderTemplate theTemplate = new HeaderTemplate(theView, 1, 3);
theTemplate.createRegion(new XYRect(0,0,1,1));
theTemplate.createRegion(new XYRect(1,0,1,1));
theTemplate.createRegion(new XYRect(2,0,1,1));
theTemplate.setRowProperties(0, new TemplateRowProperties(60));
theTemplate.setColumnProperties(0, new TemplateColumnProperties(40));
theTemplate.setColumnProperties(1, new TemplateColumnProperties(40));
theTemplate.setColumnProperties(2, new TemplateColumnProperties(40));
theTemplate.useFixedHeight(true);
theView.setDataTemplate(theTemplate);
theModel.addRow(new String[]{"the","quick","brown"});// problem arises here
theModel.addRow(new String[]{"jumps","over","the"});
theModel.addRow(new String[]{"dog","the","quick"});
add(theView);
}
class HeaderTemplate extends DataTemplate {
LabelField field1 = new LabelField("field1");
LabelField field2 = new LabelField("field2");
LabelField field3 = new LabelField("field3");
public HeaderTemplate(DataView view,int rows,int columns){
super(view, rows, columns);
}
public Field[] getDataFields(int modelRowIndex) {
TableModel theModel = (TableModel) getView().getModel();
//Get the data for the row.
Object[] data = {field1, field2, field3};
data = (Object[]) theModel.getRow(modelRowIndex);
//Create a array to hold all fields.
Field[] theDataFields = new Field[data.length];
theDataFields[0] = new LabelField(field1/*, DrawStyle.ELLIPSIS*/);
theDataFields[1] = new LabelField(field2/*, DrawStyle.ELLIPSIS*/);
theDataFields[2] = new LabelField(field3/*, DrawStyle.ELLIPSIS*/);
return theDataFields;
}
}
I know you probably are using some of this code just to test your table model, but I think your template should look more like this:
class HeaderTemplate extends DataTemplate {
public HeaderTemplate(DataView view,int rows,int columns){
super(view, rows, columns);
}
public Field[] getDataFields(int modelRowIndex) {
TableModel theModel = (TableModel) getView().getModel();
//Get the data for the row.
Object[] data = (Object[]) theModel.getRow(modelRowIndex);
//Create a array to hold all fields.
Field[] theDataFields = new Field[data.length];
theDataFields[0] = new LabelField((String)data[0], DrawStyle.ELLIPSIS);
theDataFields[1] = new LabelField((String)data[1], DrawStyle.ELLIPSIS);
theDataFields[2] = new LabelField((String)data[2], DrawStyle.ELLIPSIS);
return theDataFields;
}
}
And then add your data as an Object[]:
theModel.addRow(new Object[]{"the","quick","brown"});
Here is the BlackBerry example on this

Resources