Search results

Print and Export in React Accumulation Chart component

02 Feb 2023 / 2 minutes to read

Print

The rendered chart can be printed directly from the browser by calling the public method print.

Source
Preview
index.jsx
index.html
index.tsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective } from '@syncfusion/ej2-react-charts';
function App() {
    const data = [
        { month: 'Jan', sales: 35 }, { month: 'Feb', sales: 28 },
        { month: 'Mar', sales: 34 }, { month: 'Apr', sales: 32 },
        { month: 'May', sales: 40 }, { month: 'Jun', sales: 32 },
        { month: 'Jul', sales: 35 }, { month: 'Aug', sales: 55 },
        { month: 'Sep', sales: 38 }, { month: 'Oct', sales: 30 },
        { month: 'Nov', sales: 25 }, { month: 'Dec', sales: 32 }
    ];
    let chartInstance;
    function clickHandler() {
        chartInstance.print();
    }
    return (<div>
      <button value='print' onClick={clickHandler.bind(this)}>Print</button>
      <AccumulationChartComponent id='charts' ref={chart => chartInstance = chart}>
        <AccumulationSeriesCollectionDirective>
          <AccumulationSeriesDirective dataSource={data} xName='month' yName='sales' radius='100%'>
          </AccumulationSeriesDirective>
        </AccumulationSeriesCollectionDirective>
      </AccumulationChartComponent></div>);
}
;
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
            
    <title>Syncfusion React Chart-Category Axis</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
     <style>
        #loader {
            color: #008cff;
            height: 40px;
            left: 45%;
            position: absolute;
            top: 45%;
            width: 30%;
        }
        #charts {
            height : 350px;
            display: block;
        }
    </style>
</head>

<body>
        <div id='charts'>
            <div id='loader'>Loading....</div>
        </div>
</body>
</html>
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, Inject}
from'@syncfusion/ej2-react-charts';

function App() {

  const data: any[] = [
    { month: 'Jan', sales: 35 }, { month: 'Feb', sales: 28 },
    { month: 'Mar', sales: 34 }, { month: 'Apr', sales: 32 },
    { month: 'May', sales: 40 }, { month: 'Jun', sales: 32 },
    { month: 'Jul', sales: 35 }, { month: 'Aug', sales: 55 },
    { month: 'Sep', sales: 38 }, { month: 'Oct', sales: 30 },
    { month: 'Nov', sales: 25 }, { month: 'Dec', sales: 32 }
  ];
  let chartInstance: AccumulationChartComponent;
  function clickHandler() {
    chartInstance.print();
  }

    return (<div>
      <button value='print' onClick={clickHandler.bind(this)}>Print</button>
      <AccumulationChartComponent id='charts' ref={chart => chartInstance = chart}>
        <AccumulationSeriesCollectionDirective>
          <AccumulationSeriesDirective dataSource={data} xName='month' yName='sales' radius='100%'>
          </AccumulationSeriesDirective>
        </AccumulationSeriesCollectionDirective>
      </AccumulationChartComponent></div>)

};
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));

Export

The rendered chart can be exported to Image(jpeg or png) or SVG or PDF format by using the export method. Input parameters for this method are Export Type for format and fileName of result.

Source
Preview
index.jsx
index.html
index.tsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, Export, Inject } from '@syncfusion/ej2-react-charts';
function App() {
    const data = [
        { month: 'Jan', sales: 35 }, { month: 'Feb', sales: 28 },
        { month: 'Mar', sales: 34 }, { month: 'Apr', sales: 32 },
        { month: 'May', sales: 40 }, { month: 'Jun', sales: 32 },
        { month: 'Jul', sales: 35 }, { month: 'Aug', sales: 55 },
        { month: 'Sep', sales: 38 }, { month: 'Oct', sales: 30 },
        { month: 'Nov', sales: 25 }, { month: 'Dec', sales: 32 }
    ];
    let chartInstance;
    function clickHandler() {
        chartInstance.exportModule.export('PNG', 'charts');
    }
    return (<div><button value='print' onClick={clickHandler.bind(this)}>Export</button>
      <AccumulationChartComponent id='charts' ref={chart => chartInstance = chart}>
      <Inject services={[Export]}/>
        <AccumulationSeriesCollectionDirective>
          <AccumulationSeriesDirective dataSource={data} xName='month' yName='sales' radius='100%'>
          </AccumulationSeriesDirective>
        </AccumulationSeriesCollectionDirective>
      </AccumulationChartComponent></div>);
}
;
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
            
    <title>Syncfusion React Chart-Category Axis</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
     <style>
        #loader {
            color: #008cff;
            height: 40px;
            left: 45%;
            position: absolute;
            top: 45%;
            width: 30%;
        }
        #charts {
            height : 350px;
            display: block;
        }
    </style>
</head>

<body>
        <div id='charts'>
            <div id='loader'>Loading....</div>
        </div>
</body>
</html>
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, Export, Inject}
from'@syncfusion/ej2-react-charts';

function App() {

  const data: any[] = [
    { month: 'Jan', sales: 35 }, { month: 'Feb', sales: 28 },
    { month: 'Mar', sales: 34 }, { month: 'Apr', sales: 32 },
    { month: 'May', sales: 40 }, { month: 'Jun', sales: 32 },
    { month: 'Jul', sales: 35 }, { month: 'Aug', sales: 55 },
    { month: 'Sep', sales: 38 }, { month: 'Oct', sales: 30 },
    { month: 'Nov', sales: 25 }, { month: 'Dec', sales: 32 }
  ];
  let chartInstance: AccumulationChartComponent;
  function clickHandler() {
    chartInstance.exportModule.export('PNG', 'charts');
  }

    return (<div><button value='print' onClick={clickHandler.bind(this)}>Export</button>
      <AccumulationChartComponent id='charts' ref={chart => chartInstance = chart}>
      <Inject services={[Export]} />
        <AccumulationSeriesCollectionDirective>
          <AccumulationSeriesDirective dataSource={data} xName='month' yName='sales' radius='100%'>
          </AccumulationSeriesDirective>
        </AccumulationSeriesCollectionDirective>
      </AccumulationChartComponent></div>)

};
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));
Contents
Contents