Replies: 1 comment
-
|
The issue is that all your datasets share the same Assign a different color to each dataset: const colors = [
"rgba(75, 192, 192, 0.6)",
"rgba(255, 99, 132, 0.6)",
"rgba(54, 162, 235, 0.6)",
"rgba(255, 206, 86, 0.6)",
"rgba(153, 102, 255, 0.6)",
];
const financialData = Object.entries(complianceData).map(([symbol, details], index) => ({
label: `${symbol} Financial Ratios`,
data: [
details.financial_health_ratios["Current Ratio"],
details.financial_health_ratios["Debt-to-Equity Ratio"],
details.financial_health_ratios["Profit Margin"],
details.financial_health_ratios["Return on Equity"]
],
backgroundColor: colors[index % colors.length],
}));A few other things to verify:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
I'm building a Shariah Compliance Investment Dashboard using React and react-chartjs-2. I fetch stock data in batch from an API. The response returns valid financial ratio data for each ticker. The console log confirms all tickers are processed. However, the Bar chart only shows the dataset for the first ticker.
Expected:
All tickers from the batch should display as individual datasets on the bar chart.
What I've tried:
.map()to build datasets dynamicallyRelevant Code Snippet:
// Example of how I build chart datasets from API response
const financialData = Object.entries(complianceData).map(([symbol, details]) => ({
label:
${symbol} Financial Ratios,data: [
details.financial_health_ratios["Current Ratio"],
details.financial_health_ratios["Debt-to-Equity Ratio"],
details.financial_health_ratios["Profit Margin"],
details.financial_health_ratios["Return on Equity"]
],
backgroundColor: 'rgba(75, 192, 192, 0.6)',
}));
// In JSX
<Bar
data={{
labels: ["Current Ratio", "Debt-to-Equity Ratio", "Profit Margin", "Return on Equity"],
datasets: financialData
}}
options={{ responsive: true }}
/>
Sample:
console.log(dataset)Beta Was this translation helpful? Give feedback.
All reactions