• Demos
    • JavaScript Charts
    • JavaScript StockCharts
  • Download/NPM
    • Download CanvasJS
    • Install via NPM
  • Integrations
    Front End Technology Samples
    • React Charts
    • Angular Charts
    • Vue.js Charts New!
    • jQuery Charts
    • Dashboards
    Server Side Technology Samples
    • PHP Charts
    • Python Charts New!
    • ASP.NET MVC Charts
    • Spring MVC Charts
    • JSP Charts
  • License
  • Blog
  • Docs
    • Chart Documentation
    • StockChart Documentation
  • Support Forum
    • Chart Support
    • StockChart Support
  • My Account
My Account
  • KEY FEATURES
    • Chart with Index / Data Label
    • Chart with Zooming / Panning
    • Chart using JSON Data
    • Chart with Animation
    • Multi Series Chart
    • Chart with Multiple Axes
    • Chart with Crosshair
    • Chart with Scale Breaks
    • Chart with Logarithmic Axis
    • Performance with 50,000 Data Points
    • Responsive Charts
    • Chart with Drilldown
  • LINE CHARTS
    • Line Chart with Formatted Axes Labels
    • Dashed Line Chart
    • Multi Series Line Chart
    • Spline Chart
    • Multi Series Spline Chart
    • Step Line Chart
    • Multi Series Step Line Chart
  • BAR CHARTS
    • Bar Chart with Category Axis
    • Multi Series Bar Chart
    • Stacked Bar Chart
    • Stacked Bar 100% Chart
    • Stacked Bar 100% Chart with Indexlabel
  • COLUMN CHARTS
    • Column Chart with Category Axis
    • Multi Series Column Chart
    • Stacked Column Chart
    • Stacked Column 100% Chart
    • Stacked Column 100% Chart with Indexlabel
    • Waterfall Chart
    • Waterfall Chart with Indexlabel
  • AREA CHARTS
    • Area Chart with Date-Time Axis
    • Multi Series Area Chart
    • Spline Area Chart
    • Multi Series Spline Area Chart
    • Step Area Chart
    • Stacked Area Chart
    • Stacked Area 100% Chart
  • RANGE CHARTS
    • Range Column Chart
    • Multi Series Range Column Chart
    • Range Bar Chart
    • Multi Series Range Bar Chart
    • Range Area Chart
    • Multi Series Range Area Chart
    • Range Spline Area Chart
    • Multi Series Range Spline Area Chart
  • PIE & DOUGHNUT CHARTS
    • Pie Chart with Indexlabels
    • Pie Chart with Index Labels Placed Inside
    • Doughnut Chart
    • Doughnut Chart in Dark Theme
  • FUNNEL & PYRAMID CHARTS
    • Funnel Chart
    • Funnel Chart with Custom Neck
    • Pyramid Chart
  • FINANCIAL CHARTS
    • Candlestick Chart
    • Candlestick Chart from JSON
    • OHLC Chart
    • OHLC with Trendline
    • Box and Whisker Chart
    • Box and Whisker Chart with Customization
  • BUBBLE & SCATTER CHARTS
    • Scatter Chart
    • Scatter Chart with Custom Markers
    • Bubble Chart
  • COMBINATION CHARTS
    • Error chart
    • Error Line Chart
    • Pareto Chart
    • Combination of Column, Line and Area Chart
  • DYNAMIC CHARTS
    • Dynamic Line Chart
    • Dynamic Column Chart
    • Dynamic Multi Series Chart
  • STOCKCHARTS
    • StockChart with Numeric Axis
    • StockChart with Date-Time Axis
    • StockChart with SplineArea & Range Selector
  • ANGULAR, VUE.JS, JAVASCRIPT, JQUERY
    • Angular Charts
    • Vue.js Charts
    • jQuery Charts
    • JavaScript Charts
  • SERVER SIDE TECHNOLOGIES
    • ASP.NET MVC Charts
    • PHP Charts
    • Python Charts
    • JSP Charts
    • Spring MVC Charts

React StockChart with Date-Time Axis

Download React Chart Samples
  • React Chart Samples
  • JavaScript Chart Samples
  • Angular Chart Samples
  • Vue.js Chart Samples
  • jQuery Chart Samples
  • PHP Chart Samples
  • Python Django Chart Samples
  • ASP.NET Chart Samples
  • JSP Chart Samples
  • Spring MVC Chart Samples
  • Dashboard Samples
  • JavaScript StockChart Samples

Below example uses React to create StockChart showing Price-Volume trend using multiple charts with date-time axis.

  • React Code
/* App.js */
import React, { Component } from "react";
import CanvasJSReact from '@canvasjs/react-stockcharts';
//var CanvasJSReact = require('@canvasjs/react-stockcharts');

var CanvasJS = CanvasJSReact.CanvasJS;
var CanvasJSStockChart = CanvasJSReact.CanvasJSStockChart;


class App extends Component {
  constructor(props) {
    super(props);
    this.state = { dataPoints1: [], dataPoints2: [], dataPoints3: [], isLoaded: false };
  }

  componentDidMount() {
    //Reference: https://reactjs.org/docs/faq-ajax.html#example-using-ajax-results-to-set-local-state
    fetch("https://canvasjs.com/data/docs/ltcusd2018.json")
      .then(res => res.json())
      .then(
        (data) => {
          var dps1 = [], dps2 = [], dps3 = [];
          for (var i = 0; i < data.length; i++) {
            dps1.push({
              x: new Date(data[i].date),
              y: [
                Number(data[i].open),
                Number(data[i].high),
                Number(data[i].low),
                Number(data[i].close)
              ]
            });
            dps2.push({x: new Date(data[i].date), y: Number(data[i].volume_usd)});
            dps3.push({x: new Date(data[i].date), y: Number(data[i].close)});
          }
          this.setState({
            isLoaded: true,
            dataPoints1: dps1,
            dataPoints2: dps2,
            dataPoints3: dps3
          });
        }
      )
  }

  render() {
    const options = {
      theme: "light2",
      title:{
        text:"React StockChart with Date-Time Axis"
      },
      subtitles: [{
        text: "Price-Volume Trend"
      }],
      charts: [{
        axisX: {
          lineThickness: 5,
          tickLength: 0,
          labelFormatter: function(e) {
            return "";
          },
          crosshair: {
            enabled: true,
            snapToDataPoint: true,
            labelFormatter: function(e) {
              return "";
            }
          }
        },
        axisY: {
          title: "Litecoin Price",
          prefix: "$",
          tickLength: 0
        },
        toolTip: {
          shared: true
        },
        data: [{
          name: "Price (in USD)",
          yValueFormatString: "$#,###.##",
          type: "candlestick",
          dataPoints : this.state.dataPoints1
        }]
      },{
        height: 100,
        axisX: {
          crosshair: {
            enabled: true,
            snapToDataPoint: true
          }
        },
        axisY: {
          title: "Volume",
          prefix: "$",
          tickLength: 0
        },
        toolTip: {
          shared: true
        },
        data: [{
          name: "Volume",
          yValueFormatString: "$#,###.##",
          type: "column",
          dataPoints : this.state.dataPoints2
        }]
      }],
      navigator: {
        data: [{
          dataPoints: this.state.dataPoints3
        }],
        slider: {
          minimum: new Date("2018-05-01"),
          maximum: new Date("2018-07-01")
        }
      }
    };
    const containerProps = {
      width: "100%",
      height: "450px",
      margin: "auto"
    };
    return (
      <div> 
        <div>
          {
            // Reference: https://reactjs.org/docs/conditional-rendering.html#inline-if-with-logical--operator
            this.state.isLoaded && 
            <CanvasJSStockChart containerProps={containerProps} options = {options}
              /* onRef = {ref => this.chart = ref} */
            />
          }
        </div>
      </div>
    );
  }
}
export default App;                              

Chart Customizations

  • axisX.valueFormatString
  • xValueFormatString
  • chart.height

Note   For step by step instructions, follow our React Integration Tutorial

Quick Links

  • Chart Docs
  • StockChart Docs
  • About Us
  • FAQs

Server Side Technologies

  • ASP.NET MVC Charts
  • PHP Charts
  • JSP Charts
  • Spring MVC Charts

Front Side Technologies

  • JavaScript Charts
  • jQuery Charts
  • React Charts
  • Angular Charts
  • JavaScript StockCharts

Contact

  • Fenopix, Inc.
  • 2093 Philadelphia Pike,
  • #5678, Claymont,
  • Delaware 19703
  • United States Of America

©2025 Fenopix Privacy Policy Cookies Policy Careers