react-chartjs-2#Chart JavaScript Examples
The following examples show how to use
react-chartjs-2#Chart.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: App.js From git-insights with MIT License | 5 votes |
Chart.helpers.extend(Chart.elements.Rectangle.prototype, { draw: chartjs.draw });
Example #2
Source File: Doughnut.jsx From crypto-manager with MIT License | 5 votes |
componentDidMount() {
let userFormData = new FormData()
userFormData.set('email', '[email protected]');
userFormData.set('aadhar_card_no', 'abc123');
userFormData.set('pan_card_no', 'abc123');
var proxy = ""
if(process.env.NODE_ENV === "production")
proxy = "https://crypto-manager-prod.herokuapp.com"
axios.post(
proxy + '/user/portfolio/get',
userFormData
)
.then(res => {
const data = (res.data)
let coins = [];
let quantity = [];
let investmentPrice = [];
var totalInvestment = 0
data.forEach(record => {
coins.push(record.tick);
quantity.push(record.quantity);
investmentPrice.push(record.investmentPrice);
totalInvestment += record.investmentPrice;
})
if(totalInvestment < 999999)
totalInvestment = Math.abs(totalInvestment) > 999 ? Math.sign(totalInvestment)*((Math.abs(totalInvestment)/1000).toFixed(1)) + 'K' : Math.sign(totalInvestment)*Math.abs(totalInvestment)
else
totalInvestment = Math.sign(totalInvestment)*((Math.abs(totalInvestment)/1000000).toFixed(1)) + 'M'
// TODO: Handle more color options
let backgroundColors = ['#1b9868', '#ffd700', '#ec6d10', '#68228b', '#1134A6', '#Cs1807'];
this.setState({
Data: {
labels: coins,
datasets: [
{
label: 'Portfolio',
data: investmentPrice,
backgroundColor: backgroundColors
}
]
},
Investment: totalInvestment
})
const context = this;
Chart.pluginService.register({
beforeDraw: function(chart) {
var width = chart.chart.width,
height = chart.chart.height,
ctx = chart.chart.ctx;
ctx.restore();
var fontSize = (height / 114).toFixed(2);
ctx.font = fontSize + "em sans-serif";
ctx.textBaseline = "middle";
var text = context.state.Investment,
textX = Math.round((width - ctx.measureText(text).width) / 2),
textY = height / 1.9;
ctx.fillText(text, textX, textY);
ctx.save();
}
});
})
.catch(err => {
console.log(err);
});
}