Skip to content

Commit 0a017f0

Browse files
committed
fix error in line plot
1 parent 0fa8db7 commit 0a017f0

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

danfojs/src/plotting/plot.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,36 @@ export class Plot {
201201

202202
} else if (utils.__key_in_object(this_config, 'x') || utils.__key_in_object(this_config, 'y')) {
203203
//plot single column specified in either of param [x | y] against index
204-
let trace = {}
204+
//plot columns against index
205+
let data = []
206+
let cols_to_plot;
205207

206-
params.forEach(param => {
207-
if (!param == "layout") {
208+
if (utils.__key_in_object(this_config, "columns")) {
209+
cols_to_plot = this.____check_if_cols_exist(this_config['columns'])
210+
} else {
211+
cols_to_plot = this.ndframe.column_names
212+
}
213+
214+
cols_to_plot.forEach(c_name => {
215+
let trace = {}
216+
217+
params.forEach(param => { //TODO accept individual configuration for traces
208218
trace[param] = config[param]
219+
})
220+
if (utils.__key_in_object(this_config, 'x')) {
221+
trace["x"] = this.ndframe[this_config['x']].values
222+
trace["y"] = this.ndframe[c_name].values
223+
trace['name'] = c_name
224+
} else {
225+
trace["y"] = this.ndframe[this_config['y']].values
226+
trace["x"] = this.ndframe[c_name].values
227+
trace['name'] = c_name
209228
}
210-
})
211229

212-
if (utils.__key_in_object(this_config, 'x')) {
213-
trace['x'] = this.ndframe[this_config['x']].values
214-
trace['y'] = this.ndframe.index
215-
} else {
216-
trace['x'] = this.ndframe.index
217-
trace['y'] = this_config['y']
218-
}
230+
data.push(trace)
219231

220-
newPlot(this.div, [trace], this_config['layout']);
232+
})
233+
newPlot(this.div, data, this_config['layout']);
221234

222235
} else {
223236
//plot columns against index

0 commit comments

Comments
 (0)