“Transcendental-Programmer” commited on
Commit
96f3483
·
1 Parent(s): 2fa6289

fix: chart_generator

Browse files
Files changed (1) hide show
  1. chart_generator.py +17 -4
chart_generator.py CHANGED
@@ -16,15 +16,28 @@ class ChartGenerator:
16
  start_time = time.time()
17
  logging.info(f"Generating chart with arguments: {plot_args}")
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  fig, ax = plt.subplots()
20
- for y in plot_args['y']:
21
  color = plot_args.get('color', None)
22
  if plot_args.get('chart_type', 'line') == 'bar':
23
- ax.bar(self.data[plot_args['x']], self.data[y], label=y, color=color)
24
  else:
25
- ax.plot(self.data[plot_args['x']], self.data[y], label=y, color=color)
26
 
27
- ax.set_xlabel(plot_args['x'])
28
  ax.legend()
29
 
30
 
 
16
  start_time = time.time()
17
  logging.info(f"Generating chart with arguments: {plot_args}")
18
 
19
+ # Validate columns before plotting
20
+ x_col = plot_args['x']
21
+ y_cols = plot_args['y']
22
+ missing_cols = []
23
+ if x_col not in self.data.columns:
24
+ missing_cols.append(x_col)
25
+ for y in y_cols:
26
+ if y not in self.data.columns:
27
+ missing_cols.append(y)
28
+ if missing_cols:
29
+ logging.error(f"Missing columns in data: {missing_cols}")
30
+ raise ValueError(f"Missing columns in data: {missing_cols}")
31
+
32
  fig, ax = plt.subplots()
33
+ for y in y_cols:
34
  color = plot_args.get('color', None)
35
  if plot_args.get('chart_type', 'line') == 'bar':
36
+ ax.bar(self.data[x_col], self.data[y], label=y, color=color)
37
  else:
38
+ ax.plot(self.data[x_col], self.data[y], label=y, color=color)
39
 
40
+ ax.set_xlabel(x_col)
41
  ax.legend()
42
 
43