bar chart
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
<!-- Render different chart types based on chartType input -->
|
<!-- Render different chart types based on chartType input -->
|
||||||
<div class="chart-wrapper">
|
<div class="chart-wrapper">
|
||||||
<!-- Bar Chart -->
|
<!-- Bar Chart -->
|
||||||
<div *ngIf="chartType === 'bar'">
|
<div *ngIf="chartType === 'bar'" class="chart-canvas-container">
|
||||||
<canvas baseChart
|
<canvas baseChart
|
||||||
[datasets]="chartData"
|
[datasets]="chartData"
|
||||||
[labels]="chartLabels"
|
[labels]="chartLabels"
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Line Chart -->
|
<!-- Line Chart -->
|
||||||
<div *ngIf="chartType === 'line'">
|
<div *ngIf="chartType === 'line'" class="chart-canvas-container">
|
||||||
<canvas baseChart
|
<canvas baseChart
|
||||||
[datasets]="chartData"
|
[datasets]="chartData"
|
||||||
[labels]="chartLabels"
|
[labels]="chartLabels"
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Pie Chart -->
|
<!-- Pie Chart -->
|
||||||
<div *ngIf="chartType === 'pie'">
|
<div *ngIf="chartType === 'pie'" class="chart-canvas-container">
|
||||||
<canvas baseChart
|
<canvas baseChart
|
||||||
[datasets]="chartData"
|
[datasets]="chartData"
|
||||||
[labels]="chartLabels"
|
[labels]="chartLabels"
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Doughnut Chart -->
|
<!-- Doughnut Chart -->
|
||||||
<div *ngIf="chartType === 'doughnut'">
|
<div *ngIf="chartType === 'doughnut'" class="chart-canvas-container">
|
||||||
<canvas baseChart
|
<canvas baseChart
|
||||||
[datasets]="chartData"
|
[datasets]="chartData"
|
||||||
[labels]="chartLabels"
|
[labels]="chartLabels"
|
||||||
@@ -68,7 +68,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Bubble Chart -->
|
<!-- Bubble Chart -->
|
||||||
<div *ngIf="chartType === 'bubble'">
|
<div *ngIf="chartType === 'bubble'" class="chart-canvas-container">
|
||||||
<canvas baseChart
|
<canvas baseChart
|
||||||
[datasets]="bubbleChartData"
|
[datasets]="bubbleChartData"
|
||||||
[options]="chartOptions"
|
[options]="chartOptions"
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Radar Chart -->
|
<!-- Radar Chart -->
|
||||||
<div *ngIf="chartType === 'radar'">
|
<div *ngIf="chartType === 'radar'" class="chart-canvas-container">
|
||||||
<canvas baseChart
|
<canvas baseChart
|
||||||
[datasets]="chartData"
|
[datasets]="chartData"
|
||||||
[labels]="chartLabels"
|
[labels]="chartLabels"
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Polar Area Chart -->
|
<!-- Polar Area Chart -->
|
||||||
<div *ngIf="chartType === 'polar'">
|
<div *ngIf="chartType === 'polar'" class="chart-canvas-container">
|
||||||
<canvas baseChart
|
<canvas baseChart
|
||||||
[datasets]="chartData"
|
[datasets]="chartData"
|
||||||
[labels]="chartLabels"
|
[labels]="chartLabels"
|
||||||
@@ -106,7 +106,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Scatter Chart -->
|
<!-- Scatter Chart -->
|
||||||
<div *ngIf="chartType === 'scatter'">
|
<div *ngIf="chartType === 'scatter'" class="chart-canvas-container">
|
||||||
<canvas baseChart
|
<canvas baseChart
|
||||||
[datasets]="chartData"
|
[datasets]="chartData"
|
||||||
[options]="chartOptions"
|
[options]="chartOptions"
|
||||||
@@ -118,7 +118,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Default/Unknown Chart Type -->
|
<!-- Default/Unknown Chart Type -->
|
||||||
<div *ngIf="!['bar', 'line', 'pie', 'doughnut', 'bubble', 'radar', 'polar', 'scatter'].includes(chartType)">
|
<div *ngIf="!['bar', 'line', 'pie', 'doughnut', 'bubble', 'radar', 'polar', 'scatter'].includes(chartType)" class="chart-canvas-container">
|
||||||
<canvas baseChart
|
<canvas baseChart
|
||||||
[datasets]="chartData"
|
[datasets]="chartData"
|
||||||
[labels]="chartLabels"
|
[labels]="chartLabels"
|
||||||
|
|||||||
@@ -30,7 +30,23 @@
|
|||||||
.chart-wrapper {
|
.chart-wrapper {
|
||||||
position: relative;
|
position: relative;
|
||||||
height: calc(100% - 100px);
|
height: calc(100% - 100px);
|
||||||
min-height: 300px;
|
min-height: 400px; // Increased minimum height for better visibility
|
||||||
|
padding: 10px; // Add padding to create space around the chart
|
||||||
|
}
|
||||||
|
|
||||||
|
// Specific container for chart canvas elements
|
||||||
|
.chart-canvas-container {
|
||||||
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
padding: 15px; // Add padding around the canvas for better spacing
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
display: block;
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.filters-section {
|
.filters-section {
|
||||||
@@ -259,4 +275,8 @@
|
|||||||
.chart-wrapper {
|
.chart-wrapper {
|
||||||
min-height: 250px;
|
min-height: 250px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.chart-canvas-container {
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -255,6 +255,8 @@ export class UnifiedChartComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
this.chartOptions = {
|
this.chartOptions = {
|
||||||
responsive: true,
|
responsive: true,
|
||||||
maintainAspectRatio: false,
|
maintainAspectRatio: false,
|
||||||
|
barPercentage: 0.6, // Reduced from 0.8 to create more spacing between bars
|
||||||
|
categoryPercentage: 0.8, // Reduced from 0.9 to create more spacing between categories
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
ticks: {
|
ticks: {
|
||||||
@@ -276,7 +278,9 @@ export class UnifiedChartComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
font: {
|
font: {
|
||||||
size: 12
|
size: 12
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
// Add some padding to the y-axis to prevent bars from touching the top
|
||||||
|
suggestedMax: 10
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
@@ -286,11 +290,21 @@ export class UnifiedChartComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
labels: {
|
labels: {
|
||||||
font: {
|
font: {
|
||||||
size: 12
|
size: 12
|
||||||
}
|
},
|
||||||
|
// Add padding to legend items
|
||||||
|
padding: 20
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
enabled: true
|
enabled: true,
|
||||||
|
// Improve tooltip appearance
|
||||||
|
backgroundColor: 'rgba(0, 0, 0, 0.8)',
|
||||||
|
titleFont: {
|
||||||
|
size: 14
|
||||||
|
},
|
||||||
|
bodyFont: {
|
||||||
|
size: 12
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
layout: {
|
layout: {
|
||||||
@@ -300,6 +314,21 @@ export class UnifiedChartComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
right: 15,
|
right: 15,
|
||||||
top: 15
|
top: 15
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// Add bar chart specific options
|
||||||
|
indexAxis: 'x', // Horizontal bars
|
||||||
|
elements: {
|
||||||
|
bar: {
|
||||||
|
borderWidth: 2, // Increased border width for better visibility
|
||||||
|
borderSkipped: false, // Show all borders for better separation
|
||||||
|
// Add border color to make bars more distinct
|
||||||
|
borderColor: 'rgba(255, 255, 255, 0.8)' // White border for better separation
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Animation settings for smoother transitions
|
||||||
|
animation: {
|
||||||
|
duration: 1000,
|
||||||
|
easing: 'easeInOutQuart'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user