score:2
I've create a class for you, so you can use it anywhere:
HighChartObject = function (obj) {
if (typeof obj === 'string') obj = JSON.parse(obj);
for (var key in obj) {
this[key] = obj[key];
}
}
HighChartObject.prototype.getDataArray = function () {
var arr = [];
for (var key in this) {
if (this.hasOwnProperty(key)) {
arr.push(obj[key]);
}
}
return arr;
}
HighChartObject.prototype.getCategoriesArray = function () {
var arr = [];
for (var key in this) {
if (this.hasOwnProperty(key)) {
arr.push(key);
}
}
return arr;
}
Usage:
var json = '{ "A": 5, "B": 12, "C": 5, "D": 11, "E": 6 }';
var obj = new HighChartObject(json);
$("#container").highcharts({
xAxis: {
categories: obj.getCategoriesArray()
},
series: [
{
name: "MyName",
data: obj.getDataArray()
}
]
});
And here there is a FIDDLE, so you can play with it!
I don't know if this is exactly what you need, but I think you can improve the code for your needs, right?
I hope it can help you =)
Source: stackoverflow.com
Related Articles
- To pass dynamic json array to Highcharts Pie Chart
- dynamic highcharts with json data
- Highcharts Solid Gauge Dynamic Update Using JSON
- passing json values to highcharts from .net code behind
- passing formatting JavaScript code to HighCharts with JSON
- Highcharts Dynamic Drilldown using json
- dynamic chart with Highcharts using json
- Highcharts chart dynamic json data from sql
- Need help in binding dynamic JSON to Highcharts
- Dynamic jSON into Highcharts Pie Chart
- Multiple dynamic Highcharts on one page with json
- HIghcharts and dynamic json
- how to show mutipal dynamic highcharts based on json data
- HighCharts Bubble graph JSON as data source
- Highcharts dynamic binding in c# or json
- Adding multiple dynamic series and axes via JSON into Highcharts
- dynamic highcharts with json data every 1 second
- Highcharts displays series names but missing data points from json source
- Reload chart data via JSON with Highcharts
- Highcharts - how to have a chart with dynamic height?
- adding series to highcharts from JSON
- HighCharts - How to create dynamic chart that exports EVERYTHING
- Highcharts - set maximum range for yAxis but keep axis dynamic within that range
- Highcharts dynamic (re-)sizing in AngularJS tabs
- how to set dynamic data in highcharts
- highcharts jquery dynamic change chart type column to bar
- Dynamic update of multiple series in highcharts
- json date format to Highcharts date format
- How to pass json data to highcharts series?
- Passing Django Database Queryset to Highcharts via JSON
- Change HighCharts pointInterval after creating chart
- HighCharts Month/multiple data array error
- Create array from string - with complex types for highchart
- Trying to load flags with my temperature data from json files
- Highstock: DataGrouping & Approximation (average) on timestamp values
- How to set "Y" position in label Highcharts
- Highchart - show heatmap legend by category
- Highcharts Maps - Displaying data on Highmaps
- AngularJS Http Requests processed synchronously?
- lazy high charts rails, what is "my_id" ? in <%= high_chart("my_id4", @chart) %>
- Date not displaying correctly on x-axis in High Stock Charts
- Why chart is not rendered correctly after export?
- Combining drag of jquery to change highcharts Height using CSS
- How to add multiple series in highcharts synchronously
- Using highcharter and r shiny with reactiveValues()
- Drag and drop not working using Highcharts-React
- Create background quadrants in scatterplot
- How to set the target of highcharts bullet chart using SVG?
- Magento: TypeError: N is not a function
- HighChart on Android dynamically update