Utility Coder
← Back to Blog
Data Visualization8 min read

Chart Creation Guide: Bar, Line, Pie, and More

Create beautiful charts for data visualization. Learn when to use bar, line, pie, doughnut, and scatter charts.

By Andy Pham

Chart Creation Guide: Bar, Line, Pie, and More

Data visualization helps communicate insights effectively. Learn which chart type to use and how to create them.

Chart Types Overview

Bar Chart

  • Best for: Comparing categories
  • Shows: Discrete data points
  • Orientation: Vertical or horizontal

Line Chart

  • Best for: Trends over time
  • Shows: Continuous data
  • Features: Multiple series support

Pie Chart

  • Best for: Parts of a whole
  • Shows: Proportions
  • Limit: 5-7 slices max

Doughnut Chart

  • Best for: Same as pie, with center metric
  • Shows: Proportions with summary
  • Variant: Pie with center hole

Scatter Chart

  • Best for: Correlations
  • Shows: X-Y relationships
  • Features: Pattern detection

When to Use Each Chart

Data Type Best Chart
Categories comparison Bar
Time series Line
Part-to-whole Pie/Doughnut
Correlation Scatter
Distribution Histogram
Multiple variables Radar

Creating Charts with Chart.js

// Bar Chart
new Chart(ctx, {
  type: 'bar',
  data: {
    labels: ['Jan', 'Feb', 'Mar'],
    datasets: [{
      label: 'Sales',
      data: [12, 19, 3],
      backgroundColor: ['#ff6384', '#36a2eb', '#ffce56']
    }]
  }
});

// Line Chart
new Chart(ctx, {
  type: 'line',
  data: {
    labels: ['Jan', 'Feb', 'Mar'],
    datasets: [{
      label: 'Revenue',
      data: [1000, 1500, 1200],
      borderColor: '#36a2eb',
      fill: false
    }]
  }
});

// Pie Chart
new Chart(ctx, {
  type: 'pie',
  data: {
    labels: ['Red', 'Blue', 'Yellow'],
    datasets: [{
      data: [30, 50, 20],
      backgroundColor: ['#ff6384', '#36a2eb', '#ffce56']
    }]
  }
});

// Scatter Chart
new Chart(ctx, {
  type: 'scatter',
  data: {
    datasets: [{
      label: 'Data Points',
      data: [
        { x: 10, y: 20 },
        { x: 15, y: 25 },
        { x: 20, y: 30 }
      ],
      backgroundColor: '#ff6384'
    }]
  }
});

Chart Best Practices

Design

  • Use clear labels
  • Choose appropriate colors
  • Maintain consistent scales
  • Add legends when needed

Accessibility

  • Include alt text
  • Use patterns with colors
  • Ensure sufficient contrast
  • Provide data tables

Performance

  • Limit data points
  • Use canvas over SVG for large datasets
  • Implement lazy loading
  • Cache rendered charts

Try Our Chart Tools

Conclusion

Choose charts based on your data type and message. Good visualization makes data understandable at a glance.

Share this article