Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Join this live chat April 6, 10AM EST - QlikView to Qlik Sense REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
khan_imran
Creator II
Creator II

Macro for dynamic chart

Hello All,

I have a requirement to have dynamic chart based on selection from particular fields. In attached app, I am able to change the chart type from line chart to straight table or vice versa(through macro).

Now, I would like to have an addition of some codes in existing macro which will defined chart type basis on my selection from account field.

For example: If i select Account 1 then it will show scatter chart, if I select Account 2 then it will show line chart and if I select Account 3 then straight table will be the view.

Below is the macro which i have used in attached app.

sub SetChartType

  set chart = ActiveDocument.GetSheetObject("CH04")

  intObjectType = chart.GetObjectType

  if intObjectType = 15 then    'is currently a line chart

  chart.SetChartType  2

  else

  chart.SetChartType  4

  end if

end sub

Kindly advise how to write in macro to achieve above output.

Regards,

Imran Khan

6 Replies
hector_munoz
Specialist
Specialist

Hi Imran,

It looks like you have the same problem someone had once... Look at this thred:set Chart Type

, and if you need additional help let us know.

Regards,

H

khan_imran
Creator II
Creator II
Author

I need some macro which will change the chart type based on field selection. I have mentioned my requirement in my original post.

Regards,

Imran Khan

hector_munoz
Specialist
Specialist

OK... Take a look to the attached sample.

Regards,

H

khan_imran
Creator II
Creator II
Author

Thanks for solution, but how would you do that? I want to have just 3 charts i.e. Line Chart, Scatter Chart and Bar Chart.

Regrads,

Imran Khan

hector_munoz
Specialist
Specialist

OK Imran,

Step by step:

  • Create a chart of one of the desired types (eg bar chart) and select the type of compatible charts in fast change menu. In the below sample, we create a bar chart with fast change to bar chart, line chart and scatter chart. Take note of the objetc ID because we will need it when creating the necessary macro (in this case CH01):

    09-04-2017 13-04-56.png



  • In script, create an INLINE table with the combination of the description of charts and its code in Qlik inner codification:

MASTER:

LOAD * INLINE [

ID, DESC

0, Bar

3, Scatter

4, Line

];

  • In designer, create a field box with the description for letting the user to select the desired chart and a variable that contains tha max value of the field.
  • Create a macro that allows the application to change the chart as the user selects the chart.
  • Associate the macro to the variable change: Settings > Document Settings > Triggers > Field Event Triggers > Variable Event Triggers + OnInput and OnChange

I attach you another app.

Regards,
H

marjan_it
Creator III
Creator III

can I do this for drilldown select in dimention?