Class Chart

    • Constructor Detail

      • Chart

        public Chart​(String id)
        Basic Constructor.
        Parameters:
        id - Wicket id. Id is used in javascript, but at the moment not escaped to JavaScript identifier rules. So use only characters allowed for JavaScript declarations to avoid problems.
      • Chart

        public Chart​(String id,
                     IModel<ChartType> typeModel,
                     IModel<ChartOptions> optionModel,
                     IModel<DataTable> dataModel)
        Complete Constructor.
        Parameters:
        id - Wicket id. Id is used in javascript, but at the moment not escaped to JavaScript identifier rules. So use only characters allowed for JavaScript declarations to avoid problems. This constructor is for use without ChartLibLoader (one chart per page).
        typeModel - Model of Type of chart.
        optionModel - Model of optionModel.
        dataModel - Model of data dataModel.
      • Chart

        public Chart​(String id,
                     IModel<ChartType> typeModel,
                     IModel<ChartOptions> optionModel,
                     IModel<DataTable> dataModel,
                     ChartLibLoader loader)
        Complete Constructor.
        Parameters:
        id - Wicket id. Id is used in javascript, but at the moment not escaped to JavaScript identifier rules. So use only characters allowed for JavaScript declarations to avoid problems. This constructor is for use with ChartLibLoader (multiple charts per page).
        typeModel - Model of Type of chart.
        optionModel - Model of optionModel.
        dataModel - Model of data dataModel.
        loader - Loader to add the chart to.
    • Method Detail

      • getLoaderUrl

        public String getLoaderUrl()
        Get Google Loader URL. Can be overwritten, if Google changes URL in future.
        Returns:
        Returns LOADER_URL.
      • createLoaderItem

        public JavaScriptHeaderItem createLoaderItem()
        Create the JavaScript for the Google loader.
        Returns:
        HeaderItem for Google loader url.
      • configureAjaxUpdate

        public void configureAjaxUpdate​(AjaxRequestTarget target)
        Configure an ajax response to redraw the chart. Use this call for instance in AjaxCheckBox#onUpdate or AjaxLink#onClick. Can be used after data change or options change. See example page for usage example switching StackedPercent option on a bar chart.
        Parameters:
        target - Request target to configure.
      • getJavaScriptHeaderItem

        public JavaScriptContentHeaderItem getJavaScriptHeaderItem()
        Create the Javascript HeaderItem for the chart without dependencies for ajax.
        Returns:
        Header item for chart draw script.
      • isResponsive

        public boolean isResponsive()
        Should some JavaScript be added to make the Chart responsive. By default Google charts are not responsive, this is an extension by wicket-gchart.

        This is set to true by default.

        Returns:
        True if the chart will redraw on window resize, false if not.
      • setResponsive

        public void setResponsive​(boolean responsive)
        Set this to true if some JavaScript should be added to make the Chart responsive. By default Google charts are not responsive, this is an extension by wicket-gchart. If true a script like
         $(window).resize(function(){
           drawChart1();
         });
         
        will be rendered in head to add this functionality.
        Parameters:
        responsive - Set to true to dynamically redraw the chart on resize events. Set to false not to redraw. Default is true.
      • getLocale

        public Locale getLocale()
        The Locale is used to render a language = "de" in the load statement like in the example:
         
         // Load Google Charts for the Japanese locale.
         google.charts.load('current', {'packages':['corechart'], 'language': 'ja'});
         
        If Locale is not explicitly set and null, the wicket Component.getLocale() is returned, which is identical to Session.getLocale(). To override use setLocale(java.util.Locale).
        Overrides:
        getLocale in class Component
        Returns:
        Locale used for the package language option.
      • setLocale

        public void setLocale​(Locale locale)
        Override default Locale for the chart. See getLocale().
        Parameters:
        locale - Locale to render chart with.
      • getMapsApiKey

        public String getMapsApiKey()
        Getter for Google Maps API key for geo- and map charts. In all other charts this value will be null. Getter should never find any usage except tests and logging.
        Returns:
        Google Maps API key. Null except for Geo Charts.
      • setMapsApiKey

        public void setMapsApiKey​(String mapsApiKey)
        Setter for Google Maps API key for geo- and map charts. In all other charts this has no use. For geo- and mapcharts add this key to be rendered in package deklaration:
         
         google.charts.load('current', {
          'packages':['geochart'],
          // Note: you will need to get a mapsApiKey for your project.
          // See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings
          'mapsApiKey': 'AIzaSyD-9tSrke72PouQMnMX-a7eZSW0jkFMBWY'
         });
         
        Parameters:
        mapsApiKey - Google Maps API key.
      • setDataModel

        public final void setDataModel​(IModel<DataTable> dataModel)
      • createLoaderStatement

        protected String createLoaderStatement()
        Create the load statement of the chart lib with package, language and Maps API key declaration as defined by the chart and its ChartType.
        Returns:
        Onle line load statement to be included in a JavaScript.
      • toJavaScript

        public String toJavaScript()
        Description copied from interface: JavaScriptable
        Return the JavaScript part.
        Specified by:
        toJavaScript in interface JavaScriptable
        Returns:
        JavaScript String for use as part of chart declaration.
      • initLoaderBuilder

        protected StringBuilder initLoaderBuilder()
        Create a StringBuilder for generating Javascript. If needed the builder contains altready the chart library loader statement.
        Returns:
        Builder stub with loader statement.
      • createJavaScriptBuilder

        protected StringBuilder createJavaScriptBuilder()
        Create a builder containing the standard javascript without wrapper.
        Returns:
        Stringbuilder with already defined javascript.
      • createWrapperJavaScriptBuilder

        protected StringBuilder createWrapperJavaScriptBuilder()
        Create a builder containing the javascript with use of ChartWrapper. See ChartWrapper Class.
        Returns:
        Stringbuilder with already defined javascript.
      • toJSON

        public com.github.openjson.JSONObject toJSON()
        Description copied from interface: Jsonable
        Create the JSON serialization of the instance.
        Specified by:
        toJSON in interface Jsonable
        Returns:
        Json object for the instance.
      • getCallbackId

        public String getCallbackId()
        Make a callback identifier from chart id.
        Returns:
        Identifier for callback.
      • getChartId

        public String getChartId()
        Make a chart identifier from chart id.
        Returns:
        Identifier(js) for chart.
      • getScriptId

        public String getScriptId()
        Make a script id from chart id.
        Returns:
        Identifier(js) for chart creation script.
      • getDataTableId

        public String getDataTableId()
        Make a data table id from chart id.
        Returns:
        Identifier(js) for datatable variable.
      • getOptionsId

        public String getOptionsId()
        Make a options id from chart id.
        Returns:
        Identifier(js) for options variable.
      • getRedrawScriptId

        public String getRedrawScriptId()
        Make a script id for redraw script from chart id. This is used if chart should be responsive.
        Returns:
        Identifier(js) for chart redraw script.
      • createRedrawJavaScript

        public String createRedrawJavaScript()
        Create a a redraw script for responsive charts. The chart is redrawn on (window).resize events.
        Returns:
        Complete redraw script.