import * as React from 'react'; import JqxChart, { IChartProps, jqx } from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxchart'; import JqxTabs from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxtabs'; export interface IState extends IChartProps { source2: IChartProps["source"]; xAxis2: IChartProps["xAxis"]; seriesGroups2: IChartProps["seriesGroups"]; } class App extends React.PureComponent<{}, IState> { private myChart = React.createRef(); constructor(props: {}) { super(props); const months: string[] = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; const source: any = { datafields: [ { name: 'Date' }, { name: 'SPOpen' }, { name: 'SPHigh' }, { name: 'SPLow' }, { name: 'SPClose' }, { name: 'SPVolume' }, { name: 'SPAdjClose' } ], datatype: 'tsv', url: 'nasdaq_vs_sp500_detailed.txt' }; const dataAdapter = new jqx.dataAdapter(source); const toolTipCustomFormatFn = (value: any, itemIndex: any, serie: any, group: any, categoryValue: any, categoryAxis: any) => { const dataItem = dataAdapter.records[itemIndex]; const volume = dataItem.SPVolume; return '
Date: ' + categoryValue.getDate() + '-' + months[categoryValue.getMonth()] + '-' + categoryValue.getFullYear() + '
Open price: $' + value.open + '
Close price: $' + value.close + '
Low price: $' + value.low + '
High price: $' + value.high + '
Daily volume: ' + volume + '
'; }; const source2: any = { datafields: [ { name: 'Date' }, { name: 'S&P 500' }, { name: 'NASDAQ' } ], datatype: 'csv', url: 'nasdaq_vs_sp500.txt' }; this.state = { padding: { left: 5, top: 5, right: 5, bottom: 5 }, seriesGroups: [ { columnsMinWidth: 4, series: [ { dataFieldClose: "SPClose", dataFieldHigh: "SPHigh", dataFieldLow: "SPLow", dataFieldOpen: "SPOpen", displayText: "S&P 500", displayTextClose: "S&P Close price", displayTextHigh: "S&P High price", displayTextLow: "S&P Low price", displayTextOpen: "S&P Open price", lineWidth: 1 } ], toolTipFormatFunction: toolTipCustomFormatFn, type: 'candlestick', valueAxis: { minValue: 1500, title: { text: 'S&P 500
' } } }, { series: [ { dataField: 'SPVolume', displayText: 'Volume', lineWidth: 1 } ], type: 'line', valueAxis: { gridLines: { visible: false }, labels: { formatFunction: (value: any) => { return value / 1000000 + 'M'; } }, position: 'right', tickMarks: { visible: false }, title: { text: '
Daily Volume' } } } ], seriesGroups2: [ { series: [ { dataField: 'S&P 500', displayText: 'S&P 500' }, { dataField: 'NASDAQ', displayText: 'NASDAQ' } ], type: 'line', valueAxis: { title: { text: 'Daily Closing Price' }, unitInterval: 500, visible: true } } ], source: dataAdapter, source2: new jqx.dataAdapter(source2), titlePadding: { left: 50, top: 0, right: 0, bottom: 10 }, xAxis: { dataField: 'Date', formatFunction: (value: any) => { return value.getDate() + '-' + months[value.getMonth()] + '\'' + value.getFullYear().toString().substring(2); }, maxValue: new Date(2014, 11, 1), minValue: new Date(2014, 0, 1), type: 'date', valuesOnTicks: true }, xAxis2: { baseUnit: 'month', dataField: 'Date', gridLines: { visible: true, interval: 3 }, labels: { formatFunction: (value: any) => { return months[value.getMonth()]; } }, tickMarks: { visible: true, interval: 1 }, toolTipFormatFunction: (value: any) => { return value.getDate() + '-' + months[value.getMonth()] + '-' + value.getFullYear(); }, type: 'date', unitInterval: 1, valuesOnTicks: true } }; } public render() { return ( // @ts-ignore
); } } export default App;