Articles in this section
Category / Section

Display volume data for financial chart in React Chart.

4 mins read

This article explains how to display volume data for financial chart in the React Chart.

Customize to display volume data in the financial chart

Step 1: First, initialize the datasource.

financial-data.js

exports.chartValues = [
{
  period: new Date('2012-04-02'),
  open: 85.9757,
  high: 90.6657,
  low: 85.7685,
  close: 90.5257,
  volume: 660187068
},
{
  period: new Date('2012-04-09'),
  open: 89.4471,
  high: 92,
  low: 86.2157,
  close: 86.4614,
  volume: 912634864
},
{
  period: new Date('2012-04-16'),
  open: 87.1514,
  high: 88.6071,
  low: 81.4885,
  close: 81.8543,
  volume: 1221746066
},
{
  period: new Date('2012-04-23'),
  open: 81.5157,
  high: 88.2857,
  low: 79.2857,
  close: 86.1428,
  volume: 965935749
},
{
  period: new Date('2012-04-30'),
  open: 85.4,
  high: 85.4857,
  low: 80.7385,
  close: 80.75,
  volume: 615249365
},
{
  period: new Date('2012-05-07'),
  open: 80.2143,
  high: 82.2685,
  low: 79.8185,
  close: 80.9585,
  volume: 541742692
},
{
  period: new Date('2012-05-14'),
  open: 80.3671,
  high: 81.0728,
  low: 74.5971,
  close: 75.7685,
  volume: 708126233
},
{
  period: new Date('2012-05-21'),
  open: 76.3571,
  high: 82.3571,
  low: 76.2928,
  close: 80.3271,
  volume: 682076215
},
{
  period: new Date('2012-05-28'),
  open: 81.5571,
  high: 83.0714,
  low: 80.0743,
  close: 80.1414,
  volume: 480059584
},
{
  period: new Date('2012-06-04'),
  open: 80.2143,
  high: 82.9405,
  low: 78.3571,
  close: 82.9028,
  volume: 517577005
}];

Step 2: Initialize the CandleSeries, ColumnSeries, and other required properties. Afterward, bind the volume data to the yName of the column series by using the yName property. Then map the other values such as high, low, open, and close of the CandleSeries to their respective high, low, open, and close properties.

Index.js

<ChartComponent
 id="charts"     
 primaryXAxis={{
    valueType: 'DateTime',
    crosshairTooltip: { enable: true },
    majorGridLines: { width: 0 }
 }}
 primaryYAxis={{
    title: 'Volume',
    labelFormat: '{value}M',
    opposedPosition: true,
    majorGridLines: { width: 1 },
    lineStyle: { width: 0 }
 }}
 title="AAPL Historical">
 <Inject services={[CandleSeries, Tooltip, DateTime, ColumnSeries]}/>
 <SeriesCollectionDirective>
  <SeriesDirective
      type="Column"
      dataSource={chartValues}
      animation={{ enable: true }}
      xName="period"
      yName="volume"
      enableTooltip={false}
      name="Volume"
  />
  <SeriesDirective
      type="Candle"
      yAxisName="secondary"
      bearFillColor="#2ecd71"
      bullFillColor="#e74c3d"
      dataSource={chartValues}
      animation={{ enable: true }}
      xName="period"
      low="low"
      high="high"
      open="open"
      close="close"
  />
  </SeriesCollectionDirective>
</ChartComponent>

Step 3: Initialize the secondary axis in the axes property, set opposedPosition to true, and provide a name for the axis for mapping with the series.

<AxesDirective>
  <AxisDirective
      name="secondary"
      maximum={150}
      minimum={55}
      opposedPosition={true}
  />
</AxesDirective>

Step 4: Then map the secondary axis to the candle series by using the yAxisName property.

<SeriesDirective
 type="Candle"
 yAxisName="secondary"
 dataSource={chartValues}
 xName="period"
 low="low"
 high="high"
 open="open"
 close="close"
/>

The following screenshot portrays the results of the code snippet mentioned above.

Screenshot:

React chart to display volume data in the financial chart

View Sample in Stackblitz

Conclusion

I hope you enjoyed learning how to display volume data for financial series in the React Chart Component.

You can refer to our React Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our React Chart example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied