I am Unity beginner, so sorry in advance if my problem is easy to fix, I spent five days on it and still don't have the solution. I am trying to display chart generated by highcharts.com like this one: Clink to see the chart. I am working with Unity and Vuforia. This is my code so far:
json1.json (I took it from the highcharts website)
{
"chart": { "type": "line" },
"title": { "text": "My Chart" },
"subtitle": { "text": "My Untitled Chart" },
"exporting": {},
"series": [
{
"turboThreshold": 0,
"_symbolIndex": 0,
"name": "Level of decibels",
"marker": {},
"_colorIndex": 0
}
],
"plotOptions": {
"series": {
"dataLabels": {},
"animation": false
}
},
"tooltip": {},
"legend": {},
"lang": {},
"credits": {},
"yAxis": { "title": {} },
"data": {
"csvURL": "here is my url to csv",
"enablePolling": true,
"dataRefreshRate": "2"
},
"googleSpreadsheetKey": false,
"googleSpreadsheetWorksheet": false
}
converterJson.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;
public class ConverterJson : MonoBehaviour {
string path;
string jsonString;
void Start()
{
path = Application.streamingAssetsPath + "/json1.json";
jsonString = File.ReadAllText(path);
RootObject myObject = JsonUtility.FromJson<RootObject>(jsonString);
}
}
[Serializable]
public class Chart
{
public string type { get; set; }
}
[Serializable]
public class Title
{
public string text { get; set; }
}
[Serializable]
public class Subtitle
{
public string text { get; set; }
}
[Serializable]
public class Exporting
{
}
[Serializable]
public class Marker
{
}
[Serializable]
public class Series
{
public int turboThreshold { get; set; }
public int _symbolIndex { get; set; }
public string name { get; set; }
public Marker marker { get; set; }
public int _colorIndex { get; set; }
}
[Serializable]
public class DataLabels
{
}
[Serializable]
public class Series2
{
public DataLabels dataLabels { get; set; }
public bool animation { get; set; }
}
[Serializable]
public class PlotOptions
{
public Series2 series { get; set; }
}
[Serializable]
public class Tooltip
{
}
[Serializable]
public class Legend
{
}
[Serializable]
public class Lang
{
}
[Serializable]
public class Credits
{
}
[Serializable]
public class Title2
{
}
[Serializable]
public class YAxis
{
public Title2 title { get; set; }
}
[Serializable]
public class Data
{
public string csvURL { get; set; }
public bool enablePolling { get; set; }
public string dataRefreshRate { get; set; }
}
[Serializable]
public class RootObject
{
public Chart chart { get; set; }
public Title title { get; set; }
public Subtitle subtitle { get; set; }
public Exporting exporting { get; set; }
public List<Series> series { get; set; }
public PlotOptions plotOptions { get; set; }
public Tooltip tooltip { get; set; }
public Legend legend { get; set; }
public Lang lang { get; set; }
public Credits credits { get; set; }
public YAxis yAxis { get; set; }
public Data data { get; set; }
public bool googleSpreadsheetKey { get; set; }
public bool googleSpreadsheetWorksheet { get; set; }
}
To get Serializable classes I converted json1.json file using json2scharp website. To display the chart I dragged ConverterJson script to the plane 3D object. Everytime when I run the program, the plane is blank. I don't have any errors, just one warning:
warning CS0219: The variable `myObject' is assigned but its value is never used
I know that I missed something in my code, but I am not sure how to fix it. Thank you for your answers in advance!