Exemple #1
0
 def __init__(self, datasource, series_options, chart_options=None):
     self.user_input = locals()
     if not isinstance(datasource, PivotDataPool):
         raise APIInputError("%s must be an instance of PivotDataPool." % datasource)
     self.datasource = datasource
     self.series_options = clean_pcso(series_options, self.datasource)
     self.set_default_hcoptions()
     self.hcoptions.update(chart_options)
     # Now generate the plot
     self.generate_plot()
Exemple #2
0
 def __init__(self, datasource, series_options, chart_options=None):
     self.user_input = locals()
     if not isinstance(datasource, PivotDataPool):
         raise APIInputError("%s must be an instance of PivotDataPool." %
                             datasource)
     self.datasource = datasource
     self.series_options = clean_pcso(series_options, self.datasource)
     self.set_default_hcoptions()
     self.hcoptions.update(chart_options)
     # Now generate the plot
     self.generate_plot()
Exemple #3
0
    def __init__(self, datasource, series_options, chart_options=None):
        """Creates the PivotChart object.

        **Arguments**:

        - **datasource** (**required**) - a ``PivotDataPool`` object that
          holds the terms and other information to plot the chart from.

        - **series_options** (**required**) - specifies the options to plot
          the terms on the chart. It is of the form ::
            [{'options': {
                #any items from HighChart series. For ex.
                'type': 'column'
                },
              'terms': [
                'a_valid_term',
                'other_valid_term': {
                  #any options to override. For ex.
                 'type': 'area',
                  ...
                  },
                ...
                ]
              },
              ... #repeat dicts with 'options' & 'terms'
              ]

          Where -

          - **options** (**required**) - a ``dict``. Any of the parameters
            from the `Highcharts options object - series array
            <http://www.highcharts.com/ref/#series>`_ are valid as entries in
            the ``options`` dict except ``data`` (because data array is
            generated from your datasource by chartit). For example, ``type``,
            ``xAxis``, etc. are all valid entries here.

            .. note:: The items supplied in the options dict are not validated
               to make sure that Highcharts actually supports them. Any
               invalid options are just passed to Highcharts JS which silently
               ignores them.

          - **terms** (**required**) - a ``list``. Only terms that are present
            in the corresponding datasource are valid.

            .. note:: All the ``terms`` are plotted on the ``y-axis``. The
              **categories of the datasource are plotted on the x-axis. There
              is no option to override this.**

            Each of the ``terms`` must either be a ``str`` or a ``dict``. If
            entries are dicts, the keys need to be valid terms and the values
            need to be any options to override the default options. For
            example, ::

              [{'options': {
                  'type': 'column',
                  'yAxis': 0},
                'terms': [
                  'temperature',
                  {'rainfall': {
                      'type': 'line',
                      'yAxis': 1}}]}]

            plots a pivot column chart of temperature on yAxis: 0 and a line
            pivot chart of rainfall on yAxis: 1. This can alternatively be
            expressed as two separate entries: ::

              [{'options': {
                  'type': 'column',
                  'yAxis': 0},
                'terms': [
                    'temperature']},
               {'options': {
                  'type': 'line',
                  'yAxis': 1},
                'terms': [
                    'rainfall']}]

        - **chart_options** (*optional*) - a ``dict``. Any of the options from
          the `Highcharts options object <http://www.highcharts.com/ref/>`_
          are valid (except the options in the ``series`` array which are
          passed in the ``series_options`` argument. The following
          ``chart_options`` for example, set the chart title and the axes
          titles. ::

              {'chart': {
                 'title': {
                   'text': 'Weather Chart'}},
               'xAxis': {
                 'title': 'month'},
               'yAxis': {
                 'title': 'temperature'}}

          .. note:: The items supplied in the ``chart_options`` dict are not
             validated to make sure that Highcharts actually supports them.
             Any invalid options are just passed to Highcharts JS which
             silently ignores them.

        **Raises**:

        - ``APIInputError`` if any of the terms are not present in the
          corresponding datasource or if the ``series_options`` cannot be
          parsed.
        """
        self.user_input = locals()
        if not isinstance(datasource, PivotDataPool):
            raise APIInputError("%s must be an instance of PivotDataPool."
                                % datasource)
        self.datasource = datasource
        self.series_options = clean_pcso(series_options, self.datasource)
        if chart_options is None:
            chart_options = HCOptions({})
        self.set_default_hcoptions()
        self.hcoptions.update(chart_options)
        # Now generate the plot
        self.generate_plot()
Exemple #4
0
    def __init__(self, datasource, series_options, chart_options=None):
        """Creates the PivotChart object. 
        
        **Arguments**:
        
        - **datasource** (**required**) - a ``PivotDataPool`` object that 
          holds the terms and other information to plot the chart from.
          
        - **series_options** (**required**) - specifies the options to plot 
          the terms on the chart. It is of the form ::
            [{'options': {
                #any items from HighChart series. For ex.
                'type': 'column'
                },
              'terms': [
                'a_valid_term',
                'other_valid_term': {
                  #any options to override. For ex.
                 'type': 'area',
                  ...
                  },
                ...
                ]
              },
              ... #repeat dicts with 'options' & 'terms'
              ]

          Where - 
          
          - **options** (**required**) - a ``dict``. Any of the parameters 
            from the `Highcharts options object - series array 
            <http://www.highcharts.com/ref/#series>`_ are valid as entries in 
            the ``options`` dict except ``data`` (because data array is 
            generated from your datasource by chartit). For example, ``type``, 
            ``xAxis``, etc. are all valid entries here. 
            
            .. note:: The items supplied in the options dict are not validated 
               to make sure that Highcharts actually supports them. Any 
               invalid options are just passed to Highcharts JS which silently 
               ignores them.
               
          - **terms** (**required**) - a ``list``. Only terms that are present 
            in the corresponding datasource are valid. 
            
            .. note:: All the ``terms`` are plotted on the ``y-axis``. The 
              **categories of the datasource are plotted on the x-axis. There 
              is no option to override this.**
             
            Each of the ``terms`` must either be a ``str`` or a ``dict``. If 
            entries are dicts, the keys need to be valid terms and the values 
            need to be any options to override the default options. For 
            example, ::
            
              [{'options': {
                  'type': 'column',
                  'yAxis': 0},
                'terms': [
                  'temperature',
                  {'rainfall': {
                      'type': 'line',
                      'yAxis': 1}}]}]
            
            plots a pivot column chart of temperature on yAxis: 0 and a line 
            pivot chart of rainfall on yAxis: 1. This can alternatively be 
            expressed as two separate entries: ::
            
              [{'options': {
                  'type': 'column',
                  'yAxis': 0},
                'terms': [
                    'temperature']},
               {'options': {
                  'type': 'line',
                  'yAxis': 1},
                'terms': [
                    'rainfall']}]
                    
        - **chart_options** (*optional*) - a ``dict``. Any of the options from 
          the `Highcharts options object <http://www.highcharts.com/ref/>`_ 
          are valid (except the options in the ``series`` array which are 
          passed in the ``series_options`` argument. The following 
          ``chart_options`` for example, set the chart title and the axes 
          titles. :: 
          
              {'chart': {
                 'title': { 
                   'text': 'Weather Chart'}},
               'xAxis': {
                 'title': 'month'},
               'yAxis': {
                 'title': 'temperature'}}
                 
          .. note:: The items supplied in the ``chart_options`` dict are not 
             validated to make sure that Highcharts actually supports them. 
             Any invalid options are just passed to Highcharts JS which 
             silently ignores them.
             
        **Raises**: 
        
        - ``APIInputError`` if any of the terms are not present in the 
          corresponding datasource or if the ``series_options`` cannot be 
          parsed.
        """
        self.user_input = locals()
        if not isinstance(datasource, PivotDataPool):
            raise APIInputError("%s must be an instance of PivotDataPool." %
                                datasource)
        self.datasource = datasource
        self.series_options = clean_pcso(series_options, self.datasource)
        if chart_options is None:
            chart_options = HCOptions({})
        self.set_default_hcoptions()
        self.hcoptions.update(chart_options)
        # Now generate the plot
        self.generate_plot()