I've been trying to display a model on my screen (a simple UVSphere from Blender). I first exported it to .fbx format and then transformed to .g3db format with gdx-conv-win32.exe. I have this code so far, but all it shows me is a blank black screen... it only works with the model found in this tutorial (an .obj model) https://xoppa.github.io/blog/loading-models-using-libgdx/
package com.mygdx.game.screens;
/.../ imports
public class GameScreen extends MenuScreens {
public Environment environment;
public PerspectiveCamera cam;
public CameraInputController camController;
public ModelBatch modelBatch;
public Model model;
public ModelInstance instance;
AssetManager manager = new AssetManager();
public boolean loading;
public Array<ModelInstance> instances;
public GameScreen(ProjectSurvival game){
super();
this.game = game;
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
environment.add(new DirectionalLight().set(0.9f, 0.9f, 0.9f, 20f, 20f, 20f));
environment.add(new PointLight().set(1, 1, 1, 20, 20, 20, 500));
instances = new Array<ModelInstance>();
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(1f, 1f, 1f);
cam.lookAt(0,0,0);
cam.near = 1f;
cam.far = 300f;
cam.update();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
manager = new AssetManager();
manager.load("ship.g3db", Model.class);
loading = true;
}
private void doneLoading() {
Model test = manager.get("ship.g3db", Model.class);
ModelInstance shipInstance = new ModelInstance(test);
instances.add(shipInstance);
loading = false;
}
#Override
public void show() {
}
#Override
public void render(float delta) {
//super.render(delta);
if (loading && manager.update()) {
doneLoading();
System.out.println("loaded");
}
camController.update();
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
modelBatch.begin(cam);
modelBatch.render(instances, environment);
modelBatch.end();
}
#Override
public void resize(int width, int height) {
super.resize(width, height);
}
#Override
public void pause() {
}
#Override
public void resume() {
}
#Override
public void hide() {
}
#Override
public void dispose() {
super.dispose();
modelBatch.dispose();
model.dispose();
instances.clear();
manager.dispose();
}
}
There are several other similar topics, but none of them solves my problem... please I need help!
EDIT:
Here's my g3dj file ( I cut some parts of it cause it's extremely long):
{
"version": [ 0, 1],
"id": "",
"meshes": [
{
"attributes": ["POSITION", "NORMAL", "TEXCOORD0"],
"vertices": [
-0.724124, 0.035572, -0.598984, -0.742302, -0.159337, -0.650807, 0.028780, 0.420519,
-0.691568, 0.068115, -0.634070, -0.791498, -0.084201, -0.605335, 0.021021, 0.407816,
-0.694079, 0.034096, -0.634070, -0.878414, 0.254219, -0.404614, 0.026918, 0.405321,
// deleted (...)
-0.846887, -0.041603, -0.403719, -0.887509, -0.132389, -0.441267, 0.051316, 0.489956,
-0.826199, -0.040587, -0.445113, -0.867977, -0.072359, -0.491256, 0.049283, 0.474874,
-0.803523, -0.039472, -0.485435, -0.859127, -0.022919, -0.511185, 0.047232, 0.459797
],
"parts": [
{
"id": "Mesh_part1",
"type": "TRIANGLES",
"indices": [
0, 1, 2, 1, 0, 3, 4, 2, 5, 2, 4, 0,
2, 6, 7, 6, 2, 1, 5, 7, 8, 7, 5, 2,
0, 9, 3, 3, 9, 10, 9, 11, 10, 11, 9, 12,
9, 4, 13, 4, 9, 0, 12, 13, 14, 13, 12, 9,
// deleted (...)
3610, 3613, 3614, 137, 3614, 3613, 3614, 137, 133, 3606, 3612, 3596,
3612, 3606, 3613, 112, 3613, 3606, 3613, 112, 137, 3614, 3608, 3610,
3608, 3614, 3615, 3615, 3539, 3608, 3539, 3615, 3543, 133, 3615, 3614,
3615, 133, 134, 134, 3543, 3615, 3543, 134, 14
]
}
]
}
],
"materials": [
{
"id": "Material.001",
"ambient": [ 0.200000, 0.200000, 0.200000],
"diffuse": [ 0.800000, 0.800000, 0.800000],
"emissive": [ 0.000000, 0.000000, 0.000000],
"opacity": 0.000000,
"specular": [ 0.200000, 0.200000, 0.200000],
"shininess": 20.000000
}
],
"nodes": [
{
"id": "Sphere",
"rotation": [-0.707107, 0.000000, 0.000000, 0.707107],
"scale": [ 100.000000, 100.000000, 100.000000],
"translation": [ 0.000000, 101.334976, 0.000000],
"parts": [
{
"meshpartid": "Mesh_part1",
"materialid": "Material.001",
"uvMapping": [[]]
}
]
}
],
"animations": []
}
Since there is no accepted answer:
As described by #Xoppa In you file the opacity is set to zero, set it to 1.0000 in the gd3j file
"opacity": 0.000000
// TODO 1: find what is the property of the material in blender
// TODO 2: add to troubleshooting guide
Had the same problem but with converting LWO (Light Wave) objects to g3db / g3dj. Problem was that when LightWave is exporting to FBX format it doesn't add info about textures (I'm not actually sure if FBX format supports textures at all?). Then I switched exporting to .OBJ but again I had the problem that textures in png format are not supported. Only after using .jpg textures it started working. After that opacity was set correctly to 1. With textures it can't handle converter is setting opacity to 0.
Related
Data got from my api looks like this and I need to get the elements all inside "5f1916a05bc6cb3f055c20bc" without doing jsonResponse["5f1916a05bc6cb3f055c20bc"]["video"] because the value of "5f1916a05bc6cb3f055c20bc" changes per item. Are there any ways that I can create a model for this?
{
"5f1916a05bc6cb3f055c20bc": "{
"video": "",
"image": "",
"likes": 0,
"dislikes": 0,
"trash": 0,
"createdAt": "2020-07-23T04: 48: 00.000Z",
"id": "5f1916a05bc6cb3f055c20bc",
"author": "5eeb7edbac4dba7b6d3e68c1",
"userTag": "#doeee",
"text": "Checking again",
"campus": "University Of Technology",
"__v": 0
}
}
Just check out this code and let me know if it works:
This will dynamically get the key value pairs:
import 'dart:convert';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(home: HomePage());
}
}
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
#override
void initState() {
super.initState();
getData();
}
getData() async {
String data =
await DefaultAssetBundle.of(context).loadString("json/parse.json");
var jsonData = json.decode(data);
jsonData.forEach((key, value) {
if (key != "socketID") {
print('This is key : $key');
print('This is the value : $value');
// Following are the specific object value:
value.forEach((key, value) {
print('$key');
print('$value');
});
}
});
}
#override
Widget build(BuildContext context) {
return Scaffold(body: Text(''));
}
}
Let me know if it works.
const object1={
"socketID": "H7Cddg9o6rbyvB_TAAAC",
"5f1916a05bc6cb3f055c20bc":{
"video": "",
"image": "",
"likes": 0,
"dislikes": 0,
"trash": 0,
"createdAt": "2020-07-23T04: 48: 00.000Z",
"id": "5f1916a05bc6cb3f055c20bc",
"author": "5eeb7edbac4dba7b6d3e68c1",
"userTag": "#doeee",
"text": "Checking again",
"campus": "University Of Technology",
"__v": 0.
}
}
Var Z=Object.keys(object1);
You can print them in console to check the result
Console.log(Z);
Now this Z will hold your array of Keys in your response,then you can use For loop to get specific key value based on their Index
var Response =await http.get("Your API URL",headers: {"Accept": "application/json"},);
if (Response.statusCode == 200)
{
var data = json.decode(Response.body);
var result=Object.keys(data);
console.log(Object.keys(result));// Array ["socketID", "5f1916a05bc6cb3f055c20bc"]
console.log(result[1]); //"5f1916a05bc6cb3f055c20bc"
}
Now your required key is in result[1],just use this and parse data
I used a converter but the result was wrong...
Am trying to develop application about Covid-19 using flutter and am kinda stuck on this format of result.I need to converted to dart to keep working on the app so any help will be appreciate and thanks in advance :)
This is the result of the request from the api:
[
{
"country": "Afghanistan",
"province": null,
"timeline": {
"cases": {
"3/16/20": 21,
"3/17/20": 22,
"3/18/20": 22,
"3/19/20": 22,
"3/20/20": 24,
"3/21/20": 24,
"3/22/20": 40,
"3/23/20": 40,
"3/24/20": 74,
"3/25/20": 84,
"3/26/20": 94,
"3/27/20": 110,
"3/28/20": 110,
"3/29/20": 120,
"3/30/20": 170,
"3/31/20": 174,
"4/1/20": 237,
"4/2/20": 273,
"4/3/20": 281,
"4/4/20": 299,
"4/5/20": 349,
"4/6/20": 367,
"4/7/20": 423,
"4/8/20": 444,
"4/9/20": 484,
"4/10/20": 521,
"4/11/20": 555,
"4/12/20": 607,
"4/13/20": 665,
"4/14/20": 714
},
"deaths": {
"3/16/20": 0,
"3/17/20": 0,
"3/18/20": 0,
"3/19/20": 0,
"3/20/20": 0,
"3/21/20": 0,
"3/22/20": 1,
"3/23/20": 1,
"3/24/20": 1,
"3/25/20": 2,
"3/26/20": 4,
"3/27/20": 4,
"3/28/20": 4,
"3/29/20": 4,
"3/30/20": 4,
"3/31/20": 4,
"4/1/20": 4,
"4/2/20": 6,
"4/3/20": 6,
"4/4/20": 7,
"4/5/20": 7,
"4/6/20": 11,
"4/7/20": 14,
"4/8/20": 14,
"4/9/20": 15,
"4/10/20": 15,
"4/11/20": 18,
"4/12/20": 18,
"4/13/20": 21,
"4/14/20": 23
},
"recovered": {
"3/16/20": 1,
"3/17/20": 1,
"3/18/20": 1,
"3/19/20": 1,
"3/20/20": 1,
"3/21/20": 1,
"3/22/20": 1,
"3/23/20": 1,
"3/24/20": 1,
"3/25/20": 2,
"3/26/20": 2,
"3/27/20": 2,
"3/28/20": 2,
"3/29/20": 2,
"3/30/20": 2,
"3/31/20": 5,
"4/1/20": 5,
"4/2/20": 10,
"4/3/20": 10,
"4/4/20": 10,
"4/5/20": 15,
"4/6/20": 18,
"4/7/20": 18,
"4/8/20": 29,
"4/9/20": 32,
"4/10/20": 32,
"4/11/20": 32,
"4/12/20": 32,
"4/13/20": 32,
"4/14/20": 40
}
}
},
...
]
And this the result from converter:
class Historic {
String country;
Null province;
Timeline timeline;
Historic({this.country, this.province, this.timeline});
Historic.fromJson(Map<String, dynamic> json) {
country = json['country'];
province = json['province'];
timeline = json['timeline'] != null
? new Timeline.fromJson(json['timeline'])
: null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['country'] = this.country;
data['province'] = this.province;
if (this.timeline != null) {
data['timeline'] = this.timeline.toJson();
}
return data;
}
}
class Timeline {
Cases cases;
Cases deaths;
Cases recovered;
Timeline({this.cases, this.deaths, this.recovered});
Timeline.fromJson(Map<String, dynamic> json) {
cases = json['cases'] != null ? new Cases.fromJson(json['cases']) : null;
deaths = json['deaths'] != null ? new Cases.fromJson(json['deaths']) : null;
recovered = json['recovered'] != null
? new Cases.fromJson(json['recovered'])
: null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.cases != null) {
data['cases'] = this.cases.toJson();
}
if (this.deaths != null) {
data['deaths'] = this.deaths.toJson();
}
if (this.recovered != null) {
data['recovered'] = this.recovered.toJson();
}
return data;
}
}
class Cases {
int i31620;
int i31720;
int i31820;
int i31920;
int i32020;
int i32120;
int i32220;
int i32320;
int i32420;
int i32520;
int i32620;
int i32720;
int i32820;
int i32920;
int i33020;
int i33120;
int i4120;
int i4220;
int i4320;
int i4420;
int i4520;
int i4620;
int i4720;
int i4820;
int i4920;
int i41020;
int i41120;
int i41220;
int i41320;
int i41420;
Cases(
{this.i31620,
this.i31720,
this.i31820,
this.i31920,
this.i32020,
this.i32120,
this.i32220,
this.i32320,
this.i32420,
this.i32520,
this.i32620,
this.i32720,
this.i32820,
this.i32920,
this.i33020,
this.i33120,
this.i4120,
this.i4220,
this.i4320,
this.i4420,
this.i4520,
this.i4620,
this.i4720,
this.i4820,
this.i4920,
this.i41020,
this.i41120,
this.i41220,
this.i41320,
this.i41420});
Cases.fromJson(Map<String, dynamic> json) {
i31620 = json['3/16/20'];
i31720 = json['3/17/20'];
i31820 = json['3/18/20'];
i31920 = json['3/19/20'];
i32020 = json['3/20/20'];
i32120 = json['3/21/20'];
i32220 = json['3/22/20'];
i32320 = json['3/23/20'];
i32420 = json['3/24/20'];
i32520 = json['3/25/20'];
i32620 = json['3/26/20'];
i32720 = json['3/27/20'];
i32820 = json['3/28/20'];
i32920 = json['3/29/20'];
i33020 = json['3/30/20'];
i33120 = json['3/31/20'];
i4120 = json['4/1/20'];
i4220 = json['4/2/20'];
i4320 = json['4/3/20'];
i4420 = json['4/4/20'];
i4520 = json['4/5/20'];
i4620 = json['4/6/20'];
i4720 = json['4/7/20'];
i4820 = json['4/8/20'];
i4920 = json['4/9/20'];
i41020 = json['4/10/20'];
i41120 = json['4/11/20'];
i41220 = json['4/12/20'];
i41320 = json['4/13/20'];
i41420 = json['4/14/20'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['3/16/20'] = this.i31620;
data['3/17/20'] = this.i31720;
data['3/18/20'] = this.i31820;
data['3/19/20'] = this.i31920;
data['3/20/20'] = this.i32020;
data['3/21/20'] = this.i32120;
data['3/22/20'] = this.i32220;
data['3/23/20'] = this.i32320;
data['3/24/20'] = this.i32420;
data['3/25/20'] = this.i32520;
data['3/26/20'] = this.i32620;
data['3/27/20'] = this.i32720;
data['3/28/20'] = this.i32820;
data['3/29/20'] = this.i32920;
data['3/30/20'] = this.i33020;
data['3/31/20'] = this.i33120;
data['4/1/20'] = this.i4120;
data['4/2/20'] = this.i4220;
data['4/3/20'] = this.i4320;
data['4/4/20'] = this.i4420;
data['4/5/20'] = this.i4520;
data['4/6/20'] = this.i4620;
data['4/7/20'] = this.i4720;
data['4/8/20'] = this.i4820;
data['4/9/20'] = this.i4920;
data['4/10/20'] = this.i41020;
data['4/11/20'] = this.i41120;
data['4/12/20'] = this.i41220;
data['4/13/20'] = this.i41320;
data['4/14/20'] = this.i41420;
return data;
}
}
You could use this simple function to turn the date strings to DateTime object.
DateTime parseDate(String raw){
int year = int.parse(raw[2]);
int month = int.parse(raw[0]);
int day = int.parse(raw[1]);
return DateTime(year, month, day);
}
Update i found solution:
import 'dart:convert';
List<Historic> historicFromJson(String str) =>
List<Historic>.from(json.decode(str).map((x) => Historic.fromJson(x)));
String historicToJson(List<Historic> data) =>
json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class Historic {
String country;
String province;
Timeline timeline;
Historic({
this.country,
this.province,
this.timeline,
});
factory Historic.fromJson(Map<String, dynamic> json) => Historic(
country: json["country"],
province: json["province"] == null ? null : json["province"],
timeline: Timeline.fromJson(json["timeline"]),
);
Map<String, dynamic> toJson() => {
"country": country,
"province": province == null ? null : province,
"timeline": timeline.toJson(),
};
}
class Timeline {
Map<String, int> cases;
Map<String, int> deaths;
Map<String, int> recovered;
Timeline({
this.cases,
this.deaths,
this.recovered,
});
factory Timeline.fromJson(Map<String, dynamic> json) => Timeline(
cases:
Map.from(json["cases"]).map((k, v) => MapEntry<String, int>(k, v)),
deaths:
Map.from(json["deaths"]).map((k, v) => MapEntry<String, int>(k, v)),
recovered: Map.from(json["recovered"])
.map((k, v) => MapEntry<String, int>(k, v)),
);
Map<String, dynamic> toJson() => {
"cases": Map.from(cases).map((k, v) => MapEntry<String, dynamic>(k, v)),
"deaths":
Map.from(deaths).map((k, v) => MapEntry<String, dynamic>(k, v)),
"recovered":
Map.from(recovered).map((k, v) => MapEntry<String, dynamic>(k, v)),
};
}
An even faster way is to use this web tool for instant conversion from JSON. You just need to paste the JSON code in (remember to respect the format), choose the language output and voila!
Input (Copy this):
{
"country": "Afghanistan",
"province": null,
"timeline": {
"cases": {
"3/16/20": 21,
"3/17/20": 22,
"3/18/20": 22,
"3/19/20": 22,
"3/20/20": 24,
"3/21/20": 24,
"3/22/20": 40,
"3/23/20": 40,
"3/24/20": 74,
"3/25/20": 84,
"3/26/20": 94,
"3/27/20": 110,
"3/28/20": 110,
"3/29/20": 120,
"3/30/20": 170,
"3/31/20": 174,
"4/1/20": 237,
"4/2/20": 273,
"4/3/20": 281,
"4/4/20": 299,
"4/5/20": 349,
"4/6/20": 367,
"4/7/20": 423,
"4/8/20": 444,
"4/9/20": 484,
"4/10/20": 521,
"4/11/20": 555,
"4/12/20": 607,
"4/13/20": 665,
"4/14/20": 714
},
"deaths": {
"3/16/20": 0,
"3/17/20": 0,
"3/18/20": 0,
"3/19/20": 0,
"3/20/20": 0,
"3/21/20": 0,
"3/22/20": 1,
"3/23/20": 1,
"3/24/20": 1,
"3/25/20": 2,
"3/26/20": 4,
"3/27/20": 4,
"3/28/20": 4,
"3/29/20": 4,
"3/30/20": 4,
"3/31/20": 4,
"4/1/20": 4,
"4/2/20": 6,
"4/3/20": 6,
"4/4/20": 7,
"4/5/20": 7,
"4/6/20": 11,
"4/7/20": 14,
"4/8/20": 14,
"4/9/20": 15,
"4/10/20": 15,
"4/11/20": 18,
"4/12/20": 18,
"4/13/20": 21,
"4/14/20": 23
},
"recovered": {
"3/16/20": 1,
"3/17/20": 1,
"3/18/20": 1,
"3/19/20": 1,
"3/20/20": 1,
"3/21/20": 1,
"3/22/20": 1,
"3/23/20": 1,
"3/24/20": 1,
"3/25/20": 2,
"3/26/20": 2,
"3/27/20": 2,
"3/28/20": 2,
"3/29/20": 2,
"3/30/20": 2,
"3/31/20": 5,
"4/1/20": 5,
"4/2/20": 10,
"4/3/20": 10,
"4/4/20": 10,
"4/5/20": 15,
"4/6/20": 18,
"4/7/20": 18,
"4/8/20": 29,
"4/9/20": 32,
"4/10/20": 32,
"4/11/20": 32,
"4/12/20": 32,
"4/13/20": 32,
"4/14/20": 40
}
}
}
Output:
// To parse this JSON data, do
//
// final historic = historicFromJson(jsonString);
import 'dart:convert';
Historic historicFromJson(String str) => Historic.fromJson(json.decode(str));
String historicToJson(Historic data) => json.encode(data.toJson());
class Historic {
Historic({
this.country,
this.province,
this.timeline,
});
String country;
dynamic province;
Timeline timeline;
factory Historic.fromJson(Map<String, dynamic> json) => Historic(
country: json["country"],
province: json["province"],
timeline: Timeline.fromJson(json["timeline"]),
);
Map<String, dynamic> toJson() => {
"country": country,
"province": province,
"timeline": timeline.toJson(),
};
}
class Timeline {
Timeline({
this.cases,
this.deaths,
this.recovered,
});
Map<String, int> cases;
Map<String, int> deaths;
Map<String, int> recovered;
factory Timeline.fromJson(Map<String, dynamic> json) => Timeline(
cases: Map.from(json["cases"]).map((k, v) => MapEntry<String, int>(k, v)),
deaths: Map.from(json["deaths"]).map((k, v) => MapEntry<String, int>(k, v)),
recovered: Map.from(json["recovered"]).map((k, v) => MapEntry<String, int>(k, v)),
);
Map<String, dynamic> toJson() => {
"cases": Map.from(cases).map((k, v) => MapEntry<String, dynamic>(k, v)),
"deaths": Map.from(deaths).map((k, v) => MapEntry<String, dynamic>(k, v)),
"recovered": Map.from(recovered).map((k, v) => MapEntry<String, dynamic>(k, v)),
};
}
I am new to JSON and mvc so here is my issue. I am currently working on graphs using highcharts. I have a controller which returns a JSON object.
public JsonResult _GetChart_TrendPublicationTypeDetailed_Data(int
yearToDisplay)
{
//Types of publications to be considered
string[] publication_types = new string[] { "article", "book", "book_section", "conference_proceedings" };
//Get the list of outputs with usp authors
var uspPubs = _uspAuthoredPublications();
//List of years for which to display the data
List<int> yearRange = _getListOfYears(yearToDisplay, yearRangeFactor_10);
//Get the data
var data = from eprint_summary in localDB.Summary
where
eprint_summary.Year > (yearToDisplay - yearRangeFactor_10)
&& eprint_summary.Year <= yearToDisplay
&& publication_types.Contains(eprint_summary.TypeCode)
&& uspPubs.Contains(eprint_summary.EprintId)
//&& eprint_summary.refereed == "TRUE" //TODO: Confirm whether we need this filter in our counts
group eprint_summary by new { eprint_summary.Year, eprint_summary.TypeDesc } into typeTrend
orderby typeTrend.Key.Year, typeTrend.Key.TypeDesc
select new
{
Year = typeTrend.Key.Year,
Type = typeTrend.Key.TypeDesc,
Count = typeTrend.Count()
};
//Extract the series data
List<object> countData = new List<object>();
foreach (var item in data.ToList().Select(y => y.Type).Distinct().OrderBy(y => y))
{
List<int> yearlyData = new List<int>();
foreach (var year in yearRange)
{
var rec = data
.Where(y => y.Type == item)
.Where(y => y.Year == year)
.Select(y => y.Count).ToArray();
yearlyData.Add(
rec == null || rec.Length == 0 ? 0 : rec[0]
);
}
countData.Add(
new
{
name = item, //Name of the series
data = yearlyData.ToArray() //Array of data
}
);
}
//Form the json object using the series data and labels
return Json(
new
{
labels = yearRange.ToArray(),
series = countData
},
JsonRequestBehavior.AllowGet
);
}
The above is my JSON in controller.
I have my view as below where I am getting the JSON object but I do not know how to append to my graph as series. How would I convert the JSON object to something that the series accepts.
var seriesData = ' ';
var test = ' ';
function ajaxCall() {
$.ajax({
type: "post",
datatype: "Json",
async: true,
url: '#Url.Action("_GetChart_TrendPublicationTypeDetailed_Data", "ResearchCharts")',
data: { yearToDisplay: '#(DateTime.Now.AddYears(-1).Year.ToString())' },
success: function (data) {
seriesData = data;
test = seriesData.series;
//bindChart(test);
//alert(JSON.stringify(seriesData));
alert(JSON.stringify(test));
},
error: function () {
alert("An error occurred.");
}
});
}
//functions call
ajaxCall();
bindChart(test);
function bindChart(test) {
var test2 = [{ "name": "Book", "data": [14, 17, 9, 10, 6, 19, 6, 8, 0, 4] }, { "name": "Book Chapter", "data": [65, 74, 44, 66, 9, 23, 36, 51, 53, 36] }, { "name": "Conference Proceedings", "data": [15, 17, 27, 30, 28, 54, 35, 43, 50, 35] }, { "name": "Journal Article", "data": [178, 162, 133, 139, 133, 191, 160, 194, 149, 169] }];
$('#chartTrendsPublicationTypeDetailed').highcharts({
chart: {
type: 'line'
},
title: {
text: 'My data'
},
xAxis: {
categories: ['2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016']
},
series: test2//[{ "name": "Book", "data": [14, 17, 9, 10, 6, 19, 6, 8, 0, 4] }, { "name": "Book Chapter", "data": [65, 74, 44, 66, 9, 23, 36, 51, 53, 36] }, { "name": "Conference Proceedings", "data": [15, 17, 27, 30, 28, 54, 35, 43, 50, 35] }, { "name": "Journal Article", "data": [178, 162, 133, 139, 133, 191, 160, 194, 149, 169] }]
});
Please help, just need to somehow pass the data to highcharts.
in the picture, I have added the series manually and it works, but I need to pass in a variable which the series property accepts.
Old Highcharts rendering code:
$('#chartTrendsPublicationRankDetailed').highcharts({
chart: {
type: 'line'
},
title: {
text: 'My data'
},
xAxis: {
categories: labels
},
series: seriesData
});
New Highcharts rendering code. This accepts my JSON objects successfully and renders the graphs.
function bindChartItemType(seriesData, labels) {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'chartTrendsPublicationTypeDetailed',
type: 'line',
height: 500,
width: 500
},
credits: {
enabled: false
},
title: {
text: 'Trend of Publications by Item Type'
},
xAxis: {
categories: labels,
title: {
text: '<b>Year</b>'
}
},
yAxis: {
min:0,
title: {
text: '<b># of publications</b>'
}
},
series: seriesData
});
}
Feel free to add anything you like in the comments.
Regards
Shafraz Buksh
I currently have a WebGet method that returns JSON correctly with the nested { d: } element, is there a way to remove this?
Here is my Server Side Code and my class defining the JSON return:
[OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json)]
public List<OpenOrderHeader> GetOpenOrders()
{
return (from OH in SCMENT.CustomerOrders
select new OpenOrderHeader()
{
CustomerID = OH.CustomerId,
OrderID = OH.CustomerOrderID,
OrderUniqueNumber = OH.CustomerOrderUniqueNumber,
OrderDateCreated = OH.CustomerOrderDateCreated,
OrderDateUpdated = OH.CustomerOrderDateUpdated,
OrderLocalOnline = OH.CustomerOrderOnlineOrLocal,
BranchID = (int)OH.CustomerOrderLocalBranchID,
OrderCurrency = OH.CustomerOrderCurrency,
OrderConversionRate = OH.CustomerOrderCurrencyConversionRate,
OrderStatus = OH.CustomerOrderStatus
}
).ToList();
}
The Class:
public class OpenOrderHeader
{
public int CustomerID { get; set; }
public int OrderID { get; set; }
public int OrderUniqueNumber { get; set; }
public int NumberOfProductsOnOrder { get; set; }
public DateTime OrderDateCreated { get; set; }
public DateTime OrderDateUpdated { get; set; }
public string OrderLocalOnline { get; set; }
public int BranchID { get; set; }
public string PaymentMethod { get; set; }
public int OrderStatus { get; set; }
public string OrderCurrency { get; set; }
public decimal OrderConversionRate { get; set; }
public decimal SubTotalInclTax { get; set; }
public decimal SubTotalExclTax { get; set; }
public decimal DiscountInclTax { get; set; }
public decimal DiscountExclTax { get; set; }
public decimal ShippingInclTax { get; set; }
public decimal ShippingExclTax { get; set; }
public decimal PaymentFeeInclTax { get; set; }
public decimal PaymentFeeExclTax { get; set; }
}
the JSON:
{
"d": [
{
"__type": "OpenOrderHeader:#POS.Tracntrace.Member_Only.DAL.Models.Order",
"BranchID": -1,
"CustomerID": -1,
"DiscountExclTax": 0,
"DiscountInclTax": 0,
"NumberOfProductsOnOrder": 0,
"OrderConversionRate": 1,
"OrderCurrency": "ZAR",
"OrderDateCreated": "/Date(1359696634387+0200)/",
"OrderDateUpdated": "/Date(1359703834253+0200)/",
"OrderID": 1,
"OrderLocalOnline": "ONLINE",
"OrderStatus": 10,
"OrderUniqueNumber": 10,
"PaymentFeeExclTax": 0,
"PaymentFeeInclTax": 0,
"PaymentMethod": null,
"ShippingExclTax": 0,
"ShippingInclTax": 0,
"SubTotalExclTax": 0,
"SubTotalInclTax": 0
},
{
"__type": "OpenOrderHeader:#POS.Tracntrace.Member_Only.DAL.Models.Order",
"BranchID": -1,
"CustomerID": -1,
"DiscountExclTax": 0,
"DiscountInclTax": 0,
"NumberOfProductsOnOrder": 0,
"OrderConversionRate": 1,
"OrderCurrency": "ZAR",
"OrderDateCreated": "/Date(1359712050660+0200)/",
"OrderDateUpdated": "/Date(1359719250317+0200)/",
"OrderID": 2,
"OrderLocalOnline": "ONLINE",
"OrderStatus": 10,
"OrderUniqueNumber": 11,
"PaymentFeeExclTax": 0,
"PaymentFeeInclTax": 0,
"PaymentMethod": null,
"ShippingExclTax": 0,
"ShippingInclTax": 0,
"SubTotalExclTax": 0,
"SubTotalInclTax": 0
},
{
"__type": "OpenOrderHeader:#POS.Tracntrace.Member_Only.DAL.Models.Order",
"BranchID": -1,
"CustomerID": -1,
"DiscountExclTax": 0,
"DiscountInclTax": 0,
"NumberOfProductsOnOrder": 0,
"OrderConversionRate": 1,
"OrderCurrency": "ZAR",
"OrderDateCreated": "/Date(1359713291023+0200)/",
"OrderDateUpdated": "/Date(1359720490673+0200)/",
"OrderID": 3,
"OrderLocalOnline": "ONLINE",
"OrderStatus": 10,
"OrderUniqueNumber": 12,
"PaymentFeeExclTax": 0,
"PaymentFeeInclTax": 0,
"PaymentMethod": null,
"ShippingExclTax": 0,
"ShippingInclTax": 0,
"SubTotalExclTax": 0,
"SubTotalInclTax": 0
},
{
"__type": "OpenOrderHeader:#POS.Tracntrace.Member_Only.DAL.Models.Order",
"BranchID": -1,
"CustomerID": -1,
"DiscountExclTax": 0,
"DiscountInclTax": 0,
"NumberOfProductsOnOrder": 0,
"OrderConversionRate": 1,
"OrderCurrency": "ZAR",
"OrderDateCreated": "/Date(1359947946093+0200)/",
"OrderDateUpdated": "/Date(1359955145467+0200)/",
"OrderID": 4,
"OrderLocalOnline": "ONLINE",
"OrderStatus": 10,
"OrderUniqueNumber": 13,
"PaymentFeeExclTax": 0,
"PaymentFeeInclTax": 0,
"PaymentMethod": null,
"ShippingExclTax": 0,
"ShippingInclTax": 0,
"SubTotalExclTax": 0,
"SubTotalInclTax": 0
},
{
"__type": "OpenOrderHeader:#POS.Tracntrace.Member_Only.DAL.Models.Order",
"BranchID": -1,
"CustomerID": -1,
"DiscountExclTax": 0,
"DiscountInclTax": 0,
"NumberOfProductsOnOrder": 0,
"OrderConversionRate": 1,
"OrderCurrency": "ZAR",
"OrderDateCreated": "/Date(1359948641833+0200)/",
"OrderDateUpdated": "/Date(1359955841153+0200)/",
"OrderID": 5,
"OrderLocalOnline": "ONLINE",
"OrderStatus": 10,
"OrderUniqueNumber": 14,
"PaymentFeeExclTax": 0,
"PaymentFeeInclTax": 0,
"PaymentMethod": null,
"ShippingExclTax": 0,
"ShippingInclTax": 0,
"SubTotalExclTax": 0,
"SubTotalInclTax": 0
},
{
"__type": "OpenOrderHeader:#POS.Tracntrace.Member_Only.DAL.Models.Order",
"BranchID": -1,
"CustomerID": -1,
"DiscountExclTax": 0,
"DiscountInclTax": 0,
"NumberOfProductsOnOrder": 0,
"OrderConversionRate": 1,
"OrderCurrency": "ZAR",
"OrderDateCreated": "/Date(1359948752250+0200)/",
"OrderDateUpdated": "/Date(1359955951577+0200)/",
"OrderID": 6,
"OrderLocalOnline": "ONLINE",
"OrderStatus": 10,
"OrderUniqueNumber": 15,
"PaymentFeeExclTax": 0,
"PaymentFeeInclTax": 0,
"PaymentMethod": null,
"ShippingExclTax": 0,
"ShippingInclTax": 0,
"SubTotalExclTax": 0,
"SubTotalInclTax": 0
},
{
"__type": "OpenOrderHeader:#POS.Tracntrace.Member_Only.DAL.Models.Order",
"BranchID": -1,
"CustomerID": -1,
"DiscountExclTax": 0,
"DiscountInclTax": 0,
"NumberOfProductsOnOrder": 0,
"OrderConversionRate": 1,
"OrderCurrency": "ZAR",
"OrderDateCreated": "/Date(1359948895973+0200)/",
"OrderDateUpdated": "/Date(1359956095290+0200)/",
"OrderID": 7,
"OrderLocalOnline": "ONLINE",
"OrderStatus": 10,
"OrderUniqueNumber": 16,
"PaymentFeeExclTax": 0,
"PaymentFeeInclTax": 0,
"PaymentMethod": null,
"ShippingExclTax": 0,
"ShippingInclTax": 0,
"SubTotalExclTax": 0,
"SubTotalInclTax": 0
},
{
"__type": "OpenOrderHeader:#POS.Tracntrace.Member_Only.DAL.Models.Order",
"BranchID": -1,
"CustomerID": -1,
"DiscountExclTax": 0,
"DiscountInclTax": 0,
"NumberOfProductsOnOrder": 0,
"OrderConversionRate": 1,
"OrderCurrency": "ZAR",
"OrderDateCreated": "/Date(1359949020693+0200)/",
"OrderDateUpdated": "/Date(1359956220013+0200)/",
"OrderID": 8,
"OrderLocalOnline": "ONLINE",
"OrderStatus": 10,
"OrderUniqueNumber": 17,
"PaymentFeeExclTax": 0,
"PaymentFeeInclTax": 0,
"PaymentMethod": null,
"ShippingExclTax": 0,
"ShippingInclTax": 0,
"SubTotalExclTax": 0,
"SubTotalInclTax": 0
},
{
"__type": "OpenOrderHeader:#POS.Tracntrace.Member_Only.DAL.Models.Order",
"BranchID": -1,
"CustomerID": -1,
"DiscountExclTax": 0,
"DiscountInclTax": 0,
"NumberOfProductsOnOrder": 0,
"OrderConversionRate": 1,
"OrderCurrency": "USD",
"OrderDateCreated": "/Date(1359957893433+0200)/",
"OrderDateUpdated": "/Date(1359965238550+0200)/",
"OrderID": 9,
"OrderLocalOnline": "ONLINE",
"OrderStatus": 40,
"OrderUniqueNumber": 1,
"PaymentFeeExclTax": 0,
"PaymentFeeInclTax": 0,
"PaymentMethod": null,
"ShippingExclTax": 0,
"ShippingInclTax": 0,
"SubTotalExclTax": 0,
"SubTotalInclTax": 0
}
]
}
From what you've been saying, I think something like this should solve your problem:
JSONObject returnedObject = Your JSON data as returned from the server
JSONArray desiredArray = returnedObject.getJSONArray("d");
//retrieve the data and results from the JSONArray
for (int jsonCounter = 0; jsonCounter < desiredArray.length(); jsonCounter++) {
//Get the next object
JSONObject nextobj = desiredArray.getJSONObject(jsonCounter);
//Get the data
item1= nextobj.getString("__type");
item2= nextobj.getString("BranchID");
etc......
}
And that's your basic structure to extract the data. From the code you've posted I'm not exactly sure where this would go, but it should be enough to help you on your way and extract your data. Also bear in mind that the above code was written in Android using the included JSON parser, so will require some alterations to make it work with a different library
I've been developing a video gamish thing in AS3. I have an array to draw a game field that contains road, fire, finish gate etc. Then, I add a MovieClip that is controled via mouse by player and try to check collisions with road MovieClip.
However, I does not work... It never traces "IN". I couldn't find any error in my code -But you never be sure...
Could you give a hand to solve this problem?
Thank y'all!
Here is the code:
Declarations:
public class Player extends MovieClip
{
public var player:MovieClip;
public var road:MovieClip;
public var finish:MovieClip;
public var fire:MovieClip;
public var sting:MovieClip;
public var map:Array = new Array();
Array initialization:
/* 1 ROAD
* 2 FINISH
* 3 FIRE
* 4 STRING
*/
public function Player():void
{
map = [ [ 1, 1, 3, 3, 3, 3, 3, 3, 1, 1 ],
[ 1, 1, 3, 4, 4, 4, 4, 3, 1, 1 ],
[ 1, 1, 3, 4, 4, 4, 4, 3, 1, 1 ],
[ 1, 1, 3, 3, 3, 3, 3, 3, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 ],
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 ],
[ 1, 1, 3, 3, 3, 3, 3, 3, 1, 1 ],
[ 1, 1, 3, 4, 4, 4, 4, 3, 1, 1 ],
[ 1, 1, 3, 4, 4, 4, 4, 3, 1, 1 ],
[ 1, 1, 3, 3, 3, 3, 3, 3, 1, 1 ]
];
// 10 x 10 array
Adding hitTest function:
addEventListener( Event.ENTER_FRAME, playerHitTest );
And hitTest function:
public function playerHitTest( e:Event ):void
{
if ( player.hitTestObject( road ) )
{
trace("IN");
}
}
PS: If I make the condition !player.hitTestObject( road ), it always traces "IN".
Thanks again!
There's not enough code here to see exactly what's going on but it's obvious that the hitTest will fail because you are only checking against one road object, but according to your map array there should be many road objects.
You will need an array to store the road objects:
var roadArray:Array = [];
Wherever you create the road objects you should also be inserting them into this array:
roadArray.push(road);
Then when you perform the hitTest you must loop through the entire array and check each road object for a collision:
public function playerHitTest( e:Event ):void
{
for each(var road in roadArray)
{
if ( player.hitTestObject( road ) )
{
trace("IN");
}
}
}