• Chart Demos
  • Download
  • Integrations
    • Front End Technology Samples
      • React Charts
      • Angular Charts
      • Javascript Charts
      • jQuery Charts
    • Server Side Technology Samples
      • PHP Charts
      • ASP.NET MVC Charts
      • Spring MVC Charts
      • JSP Charts
  • Dashboards
  • License
  • Blog
  • Docs
  • Support Forum
  • My Account
  • My Account
  • OVERVIEW
    • Chart with Index Label
    • Multi Series Chart
    • Chart with Zooming & Panning
    • Chart with Animation
    • Chart With Image Overlay
    • Chart with Secondary Axis
    • Chart with Null Data
    • Chart with Dynamic Data
    • Column Chart with Reversed Axis
    • Chart with Logarithmic Axis
    • Chart using JSON Data
    • Performance With 50,000 Data Points
    • Draggable Column Chart
    • Chart with Axis / Scale Break
    • Chart with Crosshair
    • Chart with Customized Legends
    • Drilldown Chart
    • Responsive Chart
  • LINE CHARTS
    • Line Chart
    • Dashed Line Chart
    • Multi Series Line Chart
    • Line Chart with Zoom and Pan
    • Line Chart with Data Marker
    • Line Chart with Logarithmic Axis
    • Line Chart with Axis / Scale Break
    • Line Chart with Multiple Axes
    • Spline Chart
    • Multi Series Spline Chart
    • Dynamic Spline Chart
    • Spline Chart with Secondary Axis
    • Spline Chart with Legends
    • Step Line Chart
    • Multi Series Step Line Chart with Null Data
  • AREA CHARTS
    • Area Chart
    • Multi Series Area Charts
    • Spline Area Chart
    • Multi Series Spline Area Charts
    • Step Area Chart
    • Range Area Chart
    • Multi Series Range Area Charts
    • Range Spline Area Chart
    • Stacked Area Chart
    • Stacked Area 100% Chart
    • Stacked Area 100% Chart with Date-Time Axis
  • COLUMN & BAR CHARTS
    • Column Chart
    • Column Charts with Multiple Axes
    • Bar Chart
    • Multi Series Bar Chart
    • Bar Chart with Axis / Scale Break
    • Range Column Chart
    • Multi Series Range Column Chart
    • Stacked Column Chart
    • Stacked Column 100% Chart
    • Range Bar Chart
    • Stacked Bar Chart
    • Stacked Bar 100% Chart
    • Waterfall Chart
    • Multi Series Waterfall Chart
    • Waterfall Chart with Custom Colors
  • PIE & FUNNEL CHARTS
    • Pie Chart
    • Pie Chart with Legends
    • Pie Chart with Custom Radius
    • Doughnut Chart
    • Doughnut Chart with Custom Inner Radius
    • Funnel Chart
    • Funnel Chart with Custom Neck
    • Inverted Funnel Chart
    • Pyramid Chart
    • Pyramid Chart with Values represented by Area
    • Pyramid Chart With Index Labels Placed Inside
  • FINANCIAL CHARTS
    • Candlestick Chart
    • Multi Series Candlestick Chart
    • Combination of Candlestick & Line Chart
    • OHLC Chart
    • OHLC Chart from JSON Data using AJAX
  • SCATTER & BUBBLE CHARTS
    • Scatter / Point Chart
    • Multi Series Scatter / Point Chart
    • Scatter Chart with Custom Markers
    • Bubble Chart
    • Bubble Chart with Zoom & Pan
    • Bubble Chart with Custom Markers
  • BOX & WHISKER CHARTS
    • Box And Whisker Chart
    • Box and Whisker Chart with Color Customization
    • Box And Whisker Chart with Outliers
  • COMBINATION CHARTS
    • Error Chart
    • Error Line Chart
    • Error Bar Chart
    • Pareto Chart
    • Pareto Chart with Index / Data Label
    • Combination of Range Area and Line Charts
    • Combination of Column, Line and Area Chart
    • Combination of OHLC and Line Chart
  • DYNAMIC CHARTS
    • Dynamic / Live Column Chart
    • Dynamic / Live Line Chart
    • Dynamic / Live Multi Series Chart
  • ANGULAR, REACT, JQUERY
    • Angular Charts
    • React Charts
    • jQuery Charts
  • SERVER SIDE TECHNOLOGIES
    • ASP.NET MVC Charts
    • PHP Charts
    • JSP Charts
    • Spring MVC Charts

JavaScript OHLC Charts from JSON Data using AJAX

  • HTML Code Samples
  • PHP Code Samples
  • ASP.NET Code Samples
  • JSP Code Samples
  • Spring MVC Code Samples
  • Dashboard Samples

JSON data can be used as a data source for charts. It is usually good idea to read JSON data from AJAX request for OHLC Graphs as they are usually rendered with large number of data points. Apart from JSON, Chart can also be plotted from CSV, XML or text file data. However, you need to parse the data to convert it to format accepted by CanvasJS. Given example shows OHLC Chart rendered from JSON Data. It also contains source code that you can edit in-browser or save to run locally.

Try Editing The Code

window.onload = function() {

var dps = [];
var chart = new CanvasJS.Chart("chartContainer", {
	animationEnabled: true,
	exportEnabled: true,
	title: {
		text: "Intel Stock Price - January 2017"
	},
	axisX: {
		valueFormatString: "DD MMM"
	},
	axisY: {
		title: "Price",
		includeZero: false,
		prefix: "$"
	},
	data: [{
		type: "ohlc",
		name: "Intel Stock Price",
		color: "#DD7E86",
		showInLegend: true,
		yValueFormatString: "$##0.00",
		xValueType: "dateTime",
		dataPoints: dps
	}]
});

$.getJSON("https://canvasjs.com/data/gallery/javascript/intel-stock-price.json", parseData);

function parseData(result) {
	for (var i = 0; i < result.length; i++) {
		dps.push({
			x: result[i].x,
			y: result[i].y
		});
	}
	chart.render();
}

}                                

Related Customization

prefix property of the axis object can be used for setting prefixes in the axis labels. Some other commonly used customization options are color, indexLabel, showInLegend, etc.

© fenopix
  • About Us
  • FAQs
  • Careers
  • Privacy Policy
Server Side Technologies
  • ASP.NET MVC Charts
  • PHP Charts
  • JSP Charts
  • Spring MVC Charts
Front End Technologies
  • JavaScript Charts
  • jQuery Charts
  • React Charts
  • Angular Charts
Contact
  • Fenopix, Inc.
  • 340 S Lemon Ave, #8004,
  • Walnut, California 91789
  • United States Of America