Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const calculateButton = document.getElementById('calculate-risk');
+ const ctx = document.getElementById('risk-radar').getContext('2d');
+ let riskChart = null;
+
+ calculateButton.addEventListener('click', function() {
+ const age = document.getElementById('age').value;
+ const savings = document.getElementById('savings').value;
+ const experience = document.getElementById('experience').value;
+ const competition = document.getElementById('competition').value;
+
+ if (!age || !savings || !experience || !competition) {
+ alert('请填写所有选项!');
+ return;
+ }
+
+ const riskScores = calculateRiskScores(age, savings, experience, competition);
+ updateChart(riskScores);
+ updateAnalysis(riskScores);
+ });
+
+ function calculateRiskScores(age, savings, experience, competition) {
+ const scores = {
+ financial: 0,
+ market: 0,
+ experience: 0,
+ personal: 0
+ };
+
+ // Financial Risk
+ switch(savings) {
+ case 'low': scores.financial = 90; break;
+ case 'medium': scores.financial = 70; break;
+ case 'high': scores.financial = 40; break;
+ case 'very-high': scores.financial = 20; break;
+ }
+
+ // Market Risk
+ switch(competition) {
+ case 'high': scores.market = 85; break;
+ case 'medium': scores.market = 60; break;
+ case 'low': scores.market = 35; break;
+ }
+
+ // Experience Risk
+ switch(experience) {
+ case 'beginner': scores.experience = 90; break;
+ case 'intermediate': scores.experience = 65; break;
+ case 'advanced': scores.experience = 40; break;
+ case 'expert': scores.experience = 20; break;
+ }
+
+ // Personal Risk
+ switch(age) {
+ case 'young': scores.personal = 60; break;
+ case 'mid': scores.personal = 40; break;
+ case 'mature': scores.personal = 50; break;
+ case 'senior': scores.personal = 70; break;
+ }
+
+ return scores;
+ }
+
+ function updateChart(scores) {
+ if (riskChart) {
+ riskChart.destroy();
+ }
+
+ riskChart = new Chart(ctx, {
+ type: 'radar',
+ data: {
+ labels: ['财务风险', '市场风险', '经验风险', '个人风险'],
+ datasets: [{
+ label: '风险评分',
+ data: [scores.financial, scores.market, scores.experience, scores.personal],
+ backgroundColor: 'rgba(74, 144, 226, 0.2)',
+ borderColor: 'rgba(74, 144, 226, 1)',
+ pointBackgroundColor: 'rgba(74, 144, 226, 1)',
+ pointBorderColor: '#fff'
+ }]
+ },
+ options: {
+ scale: {
+ ticks: {
+ beginAtZero: true,
+ max: 100
+ }
+ }
+ }
+ });
+ }
+
+ function updateAnalysis(scores) {
+ const analysisDiv = document.getElementById('risk-analysis');
+ const avgScore = (scores.financial + scores.market + scores.experience + scores.personal) / 4;
+
+ let riskLevel = avgScore >= 70 ? '高风险' : avgScore >= 40 ? '中等风险' : '低风险';
+ let color = avgScore >= 70 ? '#e74c3c' : avgScore >= 40 ? '#f1c40f' : '#2ecc71';
+
+ let analysis = `
+
总体风险等级:${riskLevel}
+
财务风险:${getRiskDescription(scores.financial)}
+
市场风险:${getRiskDescription(scores.market)}
+
经验风险:${getRiskDescription(scores.experience)}
+
个人风险:${getRiskDescription(scores.personal)}
+
建议:
+ ${getRecommendations(scores)}
+ `;
+
+ analysisDiv.innerHTML = analysis;
+ }
+
+ function getRiskDescription(score) {
+ if (score >= 70) return `高 (${score}分)`;
+ if (score >= 40) return `中 (${score}分)`;
+ return `低 (${score}分)`;
+ }
+
+ function getRecommendations(scores) {
+ let recommendations = '
+
+ if (scores.financial >= 70) {
+ recommendations += '
建议增加应急储备金,至少达到6个月支出。';+ }
+ if (scores.market >= 70) {
+ recommendations += '
建议深入市场调研,寻找差异化竞争优势。';+ }
+ if (scores.experience >= 70) {
+ recommendations += '
建议先积累更多行业经验,或寻找经验丰富的合作伙伴。';+ }
+ if (scores.personal >= 70) {
+ recommendations += '
建议评估个人情况,可能需要更稳健的职业规划。';+ }
+
+ recommendations += '';
+ return recommendations;
+ }
+ });