diff --git a/app/models/miq_report.rb b/app/models/miq_report.rb index 234dcc995e9..6d2620e7623 100644 --- a/app/models/miq_report.rb +++ b/app/models/miq_report.rb @@ -224,4 +224,16 @@ def remove_loading_relations_for_virtual_custom_attributes vc_attributes = CustomAttributeMixin.select_virtual_custom_attributes(cols).present? include.delete(:custom_attributes) if vc_attributes.present? && include && include[:custom_attributes].blank? end + + # determine name column from headers for x-axis in chart + def chart_header_column + if graph[:column].blank? + _log.error("The column for the chart's x-axis must be defined in the report") + return + end + + chart_column = MiqExpression::Field.parse(graph[:column]).column + column_index = col_order.index { |col| col.include?(chart_column) } + headers[column_index] + end end diff --git a/lib/report_formatter/chart_common.rb b/lib/report_formatter/chart_common.rb index c25a6cd4974..cd334723d29 100644 --- a/lib/report_formatter/chart_common.rb +++ b/lib/report_formatter/chart_common.rb @@ -407,7 +407,7 @@ def build_numeric_chart_simple # Pie charts put categories in legend, else in axis labels add_axis_category_text(categories) - add_series(mri.headers[0], series) + add_series(mri.chart_header_column, series) end def build_numeric_chart_grouped @@ -438,7 +438,7 @@ def build_numeric_chart_grouped # Pie charts put categories in legend, else in axis labels add_axis_category_text(categories) - add_series(mri.headers[0], series) + add_series(mri.chart_header_column, series) end def build_numeric_chart_grouped_2dim @@ -537,7 +537,7 @@ def build_reporting_chart_other # Pie charts put categories in legend, else in axis labels add_axis_category_text(categories) - add_series(mri.headers[0], series) + add_series(mri.chart_header_column, series) end # C&U performance charts (Cluster, Host, VM based) diff --git a/spec/lib/report_formater/c3_formatter_spec.rb b/spec/lib/report_formater/c3_formatter_spec.rb index 2f3842f1638..cc56c407bae 100644 --- a/spec/lib/report_formater/c3_formatter_spec.rb +++ b/spec/lib/report_formater/c3_formatter_spec.rb @@ -46,9 +46,8 @@ it "handle long strings" do render_report(long_report) - expect(long_report.chart[:miq][:category_table][2]).to eq(long_category) - expect(long_report.chart[:miq][:name_table]['1']).to eq(long_header) + expect(long_report.chart[:miq][:name_table]['1']).to eq('RAM Size (MB)') end end diff --git a/spec/lib/report_formater/jqplot_formater_charting_counts_spec.rb b/spec/lib/report_formater/jqplot_formater_charting_counts_spec.rb index ab560ff1fd4..74a9b588da4 100644 --- a/spec/lib/report_formater/jqplot_formater_charting_counts_spec.rb +++ b/spec/lib/report_formater/jqplot_formater_charting_counts_spec.rb @@ -71,7 +71,6 @@ render_report(report) expect(report.chart[:data][0]).to eq([["linux_esx: 3", 3], ["widloze: 1", 1]]) expect(report.chart[:options][:seriesDefaults][:renderer]).to eq("jQuery.jqplot.PieRenderer") - expect(report.chart[:options][:series][0][:label]).to eq("OS Name") expect(report.chart[:options][:highlighter]).to be_truthy end end