score:5
var data = [
{"unit":"a", "status":"Stopped / Idle", "val":21.2022222222222222},
{"unit":"a", "status":"Working", "val":53.3066666666666667},
{"unit":"a", "status":"Headland Turning", "val":0.04694444444444444444},
{"unit":"a", "status":"Transport", "val":5.1425000000000000},
{"unit":"b", "status":"Stopped / Idle", "val":334.7358333333333333},
{"unit":"b", "status":"Working", "val":212.6386111111111111},
{"unit":"b", "status":"Headland Turning", "val":26.2955555555555556},
{"unit":"b", "status":"Transport", "val":0.00444444444444444444}
];
var seriesData = [];
var xCategories = [];
var i, cat;
for(i = 0; i < data.length; i++){
cat = 'Unit ' + data[i].unit;
if(xCategories.indexOf(cat) === -1){
xCategories[xCategories.length] = cat;
}
}
for(i = 0; i < data.length; i++){
if(seriesData){
var currSeries = seriesData.filter(function(seriesObject){ return seriesObject.name == data[i].status;});
if(currSeries.length === 0){
currSeries = seriesData[seriesData.length] = {name: data[i].status, data: []};
} else {
currSeries = currSeries[0];
}
var index = currSeries.data.length;
currSeries.data[index] = data[i].val;
} else {
seriesData[0] = {name: data[i].status, data: [data[i].val]}
}
}
Now that you've seriesData
and xCategories
you can instantiate the chart by using something similar to
chart = new Highchart({chart: {renderTo: 'chart-div',
type: 'column'
},
plotOptions: {column: {stacking: 'normal'}},
xAxis:{ categories: xCategories},
series: seriesData
});
EDIT: Here's the jsFiddle: http://jsfiddle.net/sujay/UMeGS/
score:1
On the HighCharts website I navigated to the Demo Gallery > HighChart demos section and clicked on Stacked column on the left side of the page. From there they had a link to a JSFiddle with a demo and from there I saw two sections of code that are pertinent to you.
The first section is the xAxis
property of the HighChart object. Here's what I changed it to:
xAxis: {
categories: ['Unit A', 'Unit B']
}
Those are going to be each of the columns that you are stacking the data upon.
The next section is the series
property. This is where you pass in the data that you are looking to graph into those columns. It looks like this:
series: [{
name: 'Stopped / Idle',
data: [21.2022222222222222, 334.7358333333333333]
}, {
name: 'Working',
data: [53.3066666666666667, 212.6386111111111111]
}, {
name: 'Headland Turning',
data: [0.04694444444444444444, 26.2955555555555556]
}, {
name: 'Transport',
data: [5.1425000000000000, 0.00444444444444444444]
}]
In this portion you specify the name of the particular type of data and then the values for each column you specified in the xAxis
property.
I played around with some of the options really quick and there is so much more that you can do with this, but here's the JSFiddle with a stacked column graph and your data.
Hope this helps!
Source: stackoverflow.com
Related Query
- How to format my json data for stack column chart in HighCharts
- How to create data in Json format for highcharts
- How to format Highcharts columnRange to get json data for temperature Min and Max
- how to create proper json data format from mysql for highcharts
- highcharts - precision for stacked column chart data labels
- How to format datetime for (x,y) pair data for Highcharts
- Write JSON parser to format data for pie chart (HighCharts)
- How to Build a Column Chart in Highcharts with Data Entered Dynamically Within a CMS
- How to show Legends for all the series data in stacked column chart Highcharts?
- Format data for Highcharts chart
- HighCharts - Single legend for two columns in a Stack Column chart
- How to format column chart data labels
- Highcharts display label for pie chart using html table as data source
- Extract data series from a JSON array for a Highcharts chart with 2 y-axis
- Highcharts how to make a set number of colors for pie chart data and drilldown data
- How can i load external json data in highcharts to show the bar chart
- Highcharts to populate data for pie chart using json object
- How to pass JSON data to update Highcharts Pie chart
- Data Conversion from SQL, C# with Linq to JSON for Highcharts Line chart
- Highcharts not displaying daily data for column chart
- How to add different series data for each categories in Stacked Column chart in Highcharts?
- How do I get DateTime from mysql and set it to json format ready for highcharts
- create column chart in highcharts dynamically from json data
- Highcharts - Column chart with legend for each data
- How to change JSON Format For load data to Highchart
- YQL finance data JSON format for use with highcharts
- Formatting PHP/MySQL data in correct JSON format for HighCharts
- Highcharts create legend for waterwall and stack column chart
- How to build a JSON data array for Highcharts display - switching values for xAxis/columns
- How to get column chart in angular using highcharts using dynamic data
More Query from same tag
- Highcharts label behind the second series (but above the first series)
- Issue configuring Highcharts/ Highstock candlestick (React JS)
- keep fixed size of the bars in Highcharts
- Changing time zone in Highchart
- How to display Highcharts x-axis time stamp labels inside tooltip?
- How to apply highchart's license
- Enable Highcharts Exporting On Click
- how to truncate the stackLabels on yaxis for a stacked Grouped column highchart
- Can highcharts drilldown of a chart, reflect on another chart?
- I am trying to include india map in my highchart code
- How I can rotate a polar chart?
- Highcharts "area" not hovering properly
- HighCharts.js: How to Create a Boxplot with stems representing confidence intervals, NOT max/min?
- Highcharts with Rails
- Highcharts : Display the labels (min, max, median etc.) in boxplot
- How to suppress the bullet point and series name in Highmaps' tooltip?
- Highstocks Plotline multi-color
- HighCharts: Color of label according to the color of pie slice
- How to disable interaction animations on line chart but keep tooltips?
- Highcharts: passing additional information to a tooltip
- highchart column comparison chart like xrange
- Highstock don't draw
- HighCharts show selected point from chart on Pie Chart
- Export powerpoint from highcharts
- plotting x y points in highchart as [[list of x points],[list of y points]]
- Highcharts stock-chart y-axis values go over 100%
- Highchart formatter function executed twice every time
- javascript array object doesn't work with Hicharts when defined through jinja (Django 2.0)
- How to make 3 levels drilldown plot in R highcharter (possible other packages)
- Highcharts mousewheel scroll event in firefox