score:3
Your current JSON data doesn't have correct naming convention for keys Q1 / 18 (TTM) Annual Guest Value
and Days Between 1st and 2nd Visits
should be something like this guestValue
and visits
. For more information on JSON naming convention please check this thread.
First you need to create a valid and proper JSON of data and then you can iterate through this JSON and create separate arrays of guestValue
and visits
. And at last pass these arrays to Highchart.
Below is complete working example.
var myJson = [{"category":1,"guestValue":0,"visits":23},{"category":2,"guestValue":96.6,"visits":45},{"category":3,"guestValue":73.2,"visits":65},{"category":4,"guestValue":60.3,"visits":85},{"category":5,"guestValue":52.5,"visits":105},{"category":6,"guestValue":46.6,"visits":125},{"category":7,"guestValue":41.4,"visits":144},{"category":8,"guestValue":37.5,"visits":163},{"category":9,"guestValue":34.4,"visits":179},{"category":10,"guestValue":31.9,"visits":199},{"category":"11-17","guestValue":25.4,"visits":258},{"category":"18-28","guestValue":17,"visits":394},{"category":"29+","guestValue":9.7,"visits":847}];
var guestValue = [];
var visits = [];
for (i=0; i < myJson.length; i++) {
guestValue.push(myJson[i].guestValue);
visits.push(myJson[i].visits)
}
Highcharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: null,
align: 'center',
verticalAlign: 'bottom',
},
xAxis: {
categories: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11-17', '18-28', '29+'],
title: {
text: 'Visits Per Customer (TTM)'
},
},
yAxis: {
min: 0,
gridLineWidth: 0,
minorGridLineWidth: 0,
title: {
text: 'Average Return Rate Overall: 64 Days',
y: 10
},
labels: {
overflow: 'justify'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.0f} </b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
bar: {
dataLabels: {
enabled: true,
}
}
},
legend: {
layout: 'horizontal',
align: 'right',
verticalAlign: 'top',
x: -25,
y: 5,
floating: true,
borderWidth: 1,
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Q1 / 18 (TTM) Annual Guest Value',
data: guestValue,
color: 'grey',
// label color
dataLabels: {
style: {
color: 'grey'
}
}
}, {
name: 'Days Between 1st and 2nd Visits',
data: visits,
color: 'green',
// label color
dataLabels: {
style: {
color: 'green'
}
}
}]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>
score:0
You can do this in following steps:
- Create an API in python or Php, which returns JSON data
- Make an ajax request to this API
- Use the JSON data which was returned from ajax request in Highchart.js
Alternatively, instead of using an API, you can store your JSON data directly in a JSON file and read file in Javascript. If your file name is data.json
then,
<script type="text/javascript" src="data.json"></script>
var mydata = JSON.parse(data);
you can access json keys from mydata
using
mydata[0].name
mydata[0].color
Source: stackoverflow.com
Related Query
- Importing JSON file into Highcharts for Bar Chart Visualization
- Load JSON file into highcharts to draw a Line Chart
- Highcharts percentage of total for simple bar chart
- How to format my json data for stack column chart in HighCharts
- Passing in Id for each data item in bar chart using highcharts
- Splitted bar chart for paired data with highcharts
- highcharts minPointLength do not work for unstacked bar chart
- Returning JSON file with cURL to use data in a HighCharts stock chart
- Loading JSON string into a pie chart in highcharts
- Highcharts bar chart json example?
- Highcharts display label for pie chart using html table as data source
- Convert group json for Highcharts Donut chart
- Time series horizontal bar chart for running queries visualization
- Highcharts stacked bar chart for multiple bars
- Remove gap in Highcharts column chart from null value from JSON file in React
- Extract data series from a JSON array for a Highcharts chart with 2 y-axis
- Gson to get Json value for a pie chart using Highcharts
- set individual color for each bar in bar chart using highcharts
- How can i load external json data in highcharts to show the bar chart
- Highcharts to populate data for pie chart using json object
- Dynamic jSON into Highcharts Pie Chart
- Loading JSON into a Highcharts pie chart
- Cannot set bar chart width for specific data, Highcharts
- Data Conversion from SQL, C# with Linq to JSON for Highcharts Line chart
- Unresponsive Script and/or high response time for bar chart using HighCharts
- HighCharts Create gradiance decress color to blur for each value on bar chart
- dynamically generating json from json for highcharts heap map chart using ajax
- giving a local json file for line chart
- How to create a legend for bar colors in a Highcharts bar chart
- dataLabels for bar chart in Highcharts not displaying for null values in 3.0.8
More Query from same tag
- Highcharts datetime axis labels according to data point groups
- Highcharts diffent color @ Temperature Line
- Highcharts animation not smooth on Chrome
- HighCharts JS - Getting multiple linear underlays on a scatter plot
- Erb array not updated after ajax post
- Highcharts small columns inside area
- Allow text input (write-back) from highchart tooltip
- How to make highchart from view table in Yii2?
- I'm getting this error when fly over the chart: TypeError: Cannot read property 'lineWidth' of undefined
- Highcharts best way to update dynamically changing exporting values?
- Trigger mousedown and include e.which in the event
- Is it possible to specify a date type to use?
- Highcharts - Change line color between points
- Highmaps: Panning programmatically
- Highcharts JS - share legend color between pie charts
- Draw charts with a Loop using HighCharts in symfony
- How to use Highcharts theme with rCharts
- Highcharts issue when dealing with 3D pie and large labels
- Highcharts customEvents plugin + Highstock Error
- Console HighCharts errors broke visualisation
- How can I have both a legend and data labels, with different labels, in Highcharts?
- json in multiple pie chart using Highchart
- Using a highstock chart with stacked series
- Windows Forms WebBrowser control in different target platform
- Setting custom colors in Highcharts drill-down maps
- Highcharts treemap link legends
- Highcharts sort series data and redraw
- Highcharts axis does not show properly values when numbers are so small
- How to get access to the chart from HighchartsReact component to ResponsiveGridLayout component when I'm using functional react component
- How can I dynamically set new data in Highcharts?