Class Data

  • All Implemented Interfaces:
    Serializable, OptionDataListener, org.zkoss.json.JSONAware

    public class Data
    extends Optionable
    The Data module provides a simplified interface for adding data to a chart from sources like CVS, HTML tables or grid views. See also the tutorial article on the Data module.

    It requires the modules/data.js file to be loaded.

    Please note that the default way of adding data in Highcharts, without the need of a module, is through the series.type.data option.

    Since:
    11.2.0.0
    Author:
    Jamson Chan
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Data()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.zkoss.json.JavaScriptValue getBeforeParse()
      Returns a callback function to modify the CSV before parsing it.
      List<List<Object>> getColumns()
      Returns a two-dimensional array representing the input data on tabular form.
      String getColumnsURL()
      Returns a URL to a remote JSON dataset, structured as a column array.
      org.zkoss.json.JavaScriptValue getComplete()
      Returns the callback that is evaluated when the data is finished loading, optionally from an external source, and parsed.
      String getCsv()
      Returns a comma delimited string to be parsed.
      String getCsvURL()
      Returns an URL to a remote CSV dataset.
      Number getDataRefreshRate()
      Returns the refresh rate for data polling when importing remote dataset by setting data.csvURL, data.rowsURL, data.columnsURL, or data.googleSpreadsheetKey.
      String getDateFormat()
      Returns which of the predefined date formats in Date.prototype.dateFormats to use to parse date values.
      String getDecimalPoint()
      Returns the decimal point used for parsing numbers in the CSV.
      Number getEndColumn()
      Returns in tabular input data, the last column (indexed by 0) to use.
      Number getEndRow()
      Returns in tabular input data, the last row (indexed by 0) to use.
      String getGoogleAPIKey()
      Returns the Google Spreadsheet API key required for access generated at API Services / Credentials.
      String getGoogleSpreadsheetKey()
      Returns the key or spreadsheetId value for a Google Spreadsheet to load.
      String getGoogleSpreadsheetRange()
      Returns the Google Spreadsheet range to use in combination with googleSpreadsheetKey.
      String getItemDelimiter()
      Returns item or cell delimiter for parsing CSV.
      String getLineDelimiter()
      Returns line delimiter for parsing CSV.
      org.zkoss.json.JavaScriptValue getParsed()
      Returns a callback function to access the parsed columns, the two-dimentional input data array directly, before they are interpreted into series data and categories.
      org.zkoss.json.JavaScriptValue getParseDate()
      Returns a callback function to parse string representations of dates into JavaScript timestamps.
      List<List<Object>> getRows()
      Returns the same as the columns input option, but defining rows intead of columns.
      String getRowsURL()
      Returns a URL to a remote JSON dataset, structured as a row array.
      Number getStartColumn()
      Returns in tabular input data, the first column (indexed by 0) to use.
      Number getStartRow()
      Returns in tabular input data, the first row (indexed by 0) to use.
      String getTable()
      Returns an HTML table or the id of such to be parsed as input data.
      boolean isEnablePolling()
      Returns enables automatic refetching of remote datasets every n seconds (defined by setting data.dataRefreshRate).
      boolean isFirstRowAsNames()
      Returns whether to use the first row in the data set as series names.
      boolean isSwitchRowsAndColumns()
      Returns switch rows and columns of the input data, so that this.columns effectively becomes the rows of the data set, and the rows are interpreted as series.
      void setBeforeParse​(org.zkoss.json.JavaScriptValue beforeParse)
      Sets a callback function to modify the CSV before parsing it.
      void setColumns​(List<List<Object>> columns)
      Sets a two-dimensional array representing the input data on tabular form.
      void setColumnsURL​(String columnsURL)
      Sets a URL to a remote JSON dataset, structured as a column array.
      void setComplete​(org.zkoss.json.JavaScriptValue complete)
      Sets the callback that is evaluated when the data is finished loading, optionally from an external source, and parsed.
      void setCsv​(String csv)
      Sets a comma delimited string to be parsed.
      void setCsvURL​(String csvURL)
      Sets an URL to a remote CSV dataset.
      void setDataRefreshRate​(Number dataRefreshRate)
      Sets the refresh rate for data polling when importing remote dataset by setting data.csvURL, data.rowsURL, data.columnsURL, or data.googleSpreadsheetKey.
      void setDateFormat​(String dateFormat)
      Sets which of the predefined date formats in Date.prototype.dateFormats to use to parse date values.
      void setDecimalPoint​(String decimalPoint)
      Sets the decimal point used for parsing numbers in the CSV.
      void setEnablePolling​(Boolean enablePolling)
      Sets enables automatic refetching of remote datasets every n seconds (defined by setting data.dataRefreshRate).
      void setEndColumn​(Number endColumn)
      Sets in tabular input data, the last column (indexed by 0) to use.
      void setEndRow​(Number endRow)
      Sets in tabular input data, the last row (indexed by 0) to use.
      void setFirstRowAsNames​(Boolean firstRowAsNames)
      Sets whether to use the first row in the data set as series names.
      void setGoogleAPIKey​(String googleAPIKey)
      Sets the Google Spreadsheet API key required for access generated at API Services / Credentials.
      void setGoogleSpreadsheetKey​(String googleSpreadsheetKey)
      Sets the key or spreadsheetId value for a Google Spreadsheet to load.
      void setGoogleSpreadsheetRange​(String googleSpreadsheetRange)
      Sets the Google Spreadsheet range to use in combination with googleSpreadsheetKey.
      void setItemDelimiter​(String itemDelimiter)
      Sets item or cell delimiter for parsing CSV.
      void setLineDelimiter​(String lineDelimiter)
      Sets line delimiter for parsing CSV.
      void setParsed​(org.zkoss.json.JavaScriptValue parsed)
      Sets a callback function to access the parsed columns, the two-dimentional input data array directly, before they are interpreted into series data and categories.
      void setParseDate​(org.zkoss.json.JavaScriptValue parseDate)
      Sets a callback function to parse string representations of dates into JavaScript timestamps.
      void setRows​(List<List<Object>> rows)
      Sets the same as the columns input option, but defining rows intead of columns.
      void setRowsURL​(String rowsURL)
      Sets a URL to a remote JSON dataset, structured as a row array.
      void setStartColumn​(Number startColumn)
      Sets in tabular input data, the first column (indexed by 0) to use.
      void setStartRow​(Number startRow)
      Sets in tabular input data, the first row (indexed by 0) to use.
      void setSwitchRowsAndColumns​(Boolean switchRowsAndColumns)
      Sets switch rows and columns of the input data, so that this.columns effectively becomes the rows of the data set, and the rows are interpreted as series.
      void setTable​(String table)
      Sets an HTML table or the id of such to be parsed as input data.
    • Constructor Detail

      • Data

        public Data()
    • Method Detail

      • getBeforeParse

        public org.zkoss.json.JavaScriptValue getBeforeParse()
        Returns a callback function to modify the CSV before parsing it. Return the modified string.

        Default: null

      • setBeforeParse

        public void setBeforeParse​(org.zkoss.json.JavaScriptValue beforeParse)
        Sets a callback function to modify the CSV before parsing it. Return the modified string.

        Default: null

      • getColumns

        public List<List<Object>> getColumns()
        Returns a two-dimensional array representing the input data on tabular form. This input can be used when the data is already parsed, for example from a grid view component. Each cell can be a string or number. If not switchRowsAndColumns is set, the columns are interpreted as series.

        Default: null

      • setColumns

        public void setColumns​(List<List<Object>> columns)
        Sets a two-dimensional array representing the input data on tabular form. This input can be used when the data is already parsed, for example from a grid view component. Each cell can be a string or number. If not switchRowsAndColumns is set, the columns are interpreted as series.

        Default: null

      • getColumnsURL

        public String getColumnsURL()
        Returns a URL to a remote JSON dataset, structured as a column array. Will be fetched when the chart is created using Ajax.

        Default: null

      • setColumnsURL

        public void setColumnsURL​(String columnsURL)
        Sets a URL to a remote JSON dataset, structured as a column array. Will be fetched when the chart is created using Ajax.

        Default: null

      • getComplete

        public org.zkoss.json.JavaScriptValue getComplete()
        Returns the callback that is evaluated when the data is finished loading, optionally from an external source, and parsed. The first argument passed is a finished chart options object, containing the series. These options can be extended with additional options and passed directly to the chart constructor.

        Default: null

      • setComplete

        public void setComplete​(org.zkoss.json.JavaScriptValue complete)
        Sets the callback that is evaluated when the data is finished loading, optionally from an external source, and parsed. The first argument passed is a finished chart options object, containing the series. These options can be extended with additional options and passed directly to the chart constructor.

        Default: null

      • getCsv

        public String getCsv()
        Returns a comma delimited string to be parsed. Related options are startRow, endRow, startColumn and endColumn to delimit what part of the table is used. The lineDelimiter and itemDelimiter options define the CSV delimiter formats.

        The built-in CSV parser doesn't support all flavours of CSV, so in some cases it may be necessary to use an external CSV parser. See this example of parsing CSV through the MIT licensed Papa Parse library.

        Default: null

      • setCsv

        public void setCsv​(String csv)
        Sets a comma delimited string to be parsed. Related options are startRow, endRow, startColumn and endColumn to delimit what part of the table is used. The lineDelimiter and itemDelimiter options define the CSV delimiter formats.

        The built-in CSV parser doesn't support all flavours of CSV, so in some cases it may be necessary to use an external CSV parser. See this example of parsing CSV through the MIT licensed Papa Parse library.

        Default: null

      • getCsvURL

        public String getCsvURL()
        Returns an URL to a remote CSV dataset. Will be fetched when the chart is created using Ajax.

        Default: null

      • setCsvURL

        public void setCsvURL​(String csvURL)
        Sets an URL to a remote CSV dataset. Will be fetched when the chart is created using Ajax.

        Default: null

      • getDataRefreshRate

        public Number getDataRefreshRate()
        Returns the refresh rate for data polling when importing remote dataset by setting data.csvURL, data.rowsURL, data.columnsURL, or data.googleSpreadsheetKey.

        Note that polling must be enabled by setting data.enablePolling to true.

        The value is the number of seconds between pollings. It cannot be set to less than 1 second.

        Default: 1

      • setDataRefreshRate

        public void setDataRefreshRate​(Number dataRefreshRate)
        Sets the refresh rate for data polling when importing remote dataset by setting data.csvURL, data.rowsURL, data.columnsURL, or data.googleSpreadsheetKey.

        Note that polling must be enabled by setting data.enablePolling to true.

        The value is the number of seconds between pollings. It cannot be set to less than 1 second.

        Default: 1

      • getDateFormat

        public String getDateFormat()
        Returns which of the predefined date formats in Date.prototype.dateFormats to use to parse date values.

        Defaults to a best guess based on what format gives valid and ordered dates. Valid options include: YYYY/mm/dd, dd/mm/YYYY, mm/dd/YYYY, dd/mm/YY, mm/dd/YY.

        Default: null

      • setDateFormat

        public void setDateFormat​(String dateFormat)
        Sets which of the predefined date formats in Date.prototype.dateFormats to use to parse date values.

        Defaults to a best guess based on what format gives valid and ordered dates. Valid options include: YYYY/mm/dd, dd/mm/YYYY, mm/dd/YYYY, dd/mm/YY, mm/dd/YY.

        Default: null

      • getDecimalPoint

        public String getDecimalPoint()
        Returns the decimal point used for parsing numbers in the CSV.

        If both this and data.delimiter is set to undefined, the parser will attempt to deduce the decimal point automatically.

        Default: "."

      • setDecimalPoint

        public void setDecimalPoint​(String decimalPoint)
        Sets the decimal point used for parsing numbers in the CSV.

        If both this and data.delimiter is set to undefined, the parser will attempt to deduce the decimal point automatically.

        Default: "."

      • isEnablePolling

        public boolean isEnablePolling()
        Returns enables automatic refetching of remote datasets every n seconds (defined by setting data.dataRefreshRate).

        Only works when either data.csvURL, data.rowsURL, data.columnsURL, or data.googleSpreadsheetKey.

        Default: false

      • setEnablePolling

        public void setEnablePolling​(Boolean enablePolling)
        Sets enables automatic refetching of remote datasets every n seconds (defined by setting data.dataRefreshRate).

        Only works when either data.csvURL, data.rowsURL, data.columnsURL, or data.googleSpreadsheetKey.

        Default: false

      • getEndColumn

        public Number getEndColumn()
        Returns in tabular input data, the last column (indexed by 0) to use.

        Defaults to the last column containing data.

        Default: null

      • setEndColumn

        public void setEndColumn​(Number endColumn)
        Sets in tabular input data, the last column (indexed by 0) to use.

        Defaults to the last column containing data.

        Default: null

      • getEndRow

        public Number getEndRow()
        Returns in tabular input data, the last row (indexed by 0) to use.

        Defaults to the last row containing data.

        Default: null

      • setEndRow

        public void setEndRow​(Number endRow)
        Sets in tabular input data, the last row (indexed by 0) to use.

        Defaults to the last row containing data.

        Default: null

      • isFirstRowAsNames

        public boolean isFirstRowAsNames()
        Returns whether to use the first row in the data set as series names.

        Default: true

      • setFirstRowAsNames

        public void setFirstRowAsNames​(Boolean firstRowAsNames)
        Sets whether to use the first row in the data set as series names.

        Default: true

      • getGoogleAPIKey

        public String getGoogleAPIKey()
        Returns the Google Spreadsheet API key required for access generated at API Services / Credentials. See a comprehensive tutorial for setting up the key at the Hands-On Data Visualization book website.

        Default: null

      • setGoogleAPIKey

        public void setGoogleAPIKey​(String googleAPIKey)
        Sets the Google Spreadsheet API key required for access generated at API Services / Credentials. See a comprehensive tutorial for setting up the key at the Hands-On Data Visualization book website.

        Default: null

      • getGoogleSpreadsheetKey

        public String getGoogleSpreadsheetKey()
        Returns the key or spreadsheetId value for a Google Spreadsheet to load. See developers.google.com for how to find the spreadsheetId.

        In order for Google Sheets to load, a valid googleAPIKey must also be given.

        Default: null

      • setGoogleSpreadsheetKey

        public void setGoogleSpreadsheetKey​(String googleSpreadsheetKey)
        Sets the key or spreadsheetId value for a Google Spreadsheet to load. See developers.google.com for how to find the spreadsheetId.

        In order for Google Sheets to load, a valid googleAPIKey must also be given.

        Default: null

      • getGoogleSpreadsheetRange

        public String getGoogleSpreadsheetRange()
        Returns the Google Spreadsheet range to use in combination with googleSpreadsheetKey. See developers.google.com for details.

        If given, it takes precedence over startColumn, endColumn, startRow and endRow.

        Default: null

      • setGoogleSpreadsheetRange

        public void setGoogleSpreadsheetRange​(String googleSpreadsheetRange)
        Sets the Google Spreadsheet range to use in combination with googleSpreadsheetKey. See developers.google.com for details.

        If given, it takes precedence over startColumn, endColumn, startRow and endRow.

        Default: null

      • getItemDelimiter

        public String getItemDelimiter()
        Returns item or cell delimiter for parsing CSV. Defaults to the tab character \t if a tab character is found in the CSV string, if not it defaults to ,.

        If this is set to false or undefined, the parser will attempt to deduce the delimiter automatically.

        Default: null

      • setItemDelimiter

        public void setItemDelimiter​(String itemDelimiter)
        Sets item or cell delimiter for parsing CSV. Defaults to the tab character \t if a tab character is found in the CSV string, if not it defaults to ,.

        If this is set to false or undefined, the parser will attempt to deduce the delimiter automatically.

        Default: null

      • getLineDelimiter

        public String getLineDelimiter()
        Returns line delimiter for parsing CSV.

        Default: "\n"

      • setLineDelimiter

        public void setLineDelimiter​(String lineDelimiter)
        Sets line delimiter for parsing CSV.

        Default: "\n"

      • getParsed

        public org.zkoss.json.JavaScriptValue getParsed()
        Returns a callback function to access the parsed columns, the two-dimentional input data array directly, before they are interpreted into series data and categories. Return false to stop completion, or call this.complete() to continue async.

        Default: null

      • setParsed

        public void setParsed​(org.zkoss.json.JavaScriptValue parsed)
        Sets a callback function to access the parsed columns, the two-dimentional input data array directly, before they are interpreted into series data and categories. Return false to stop completion, or call this.complete() to continue async.

        Default: null

      • getParseDate

        public org.zkoss.json.JavaScriptValue getParseDate()
        Returns a callback function to parse string representations of dates into JavaScript timestamps. Should return an integer timestamp on success.

        Default: null

      • setParseDate

        public void setParseDate​(org.zkoss.json.JavaScriptValue parseDate)
        Sets a callback function to parse string representations of dates into JavaScript timestamps. Should return an integer timestamp on success.

        Default: null

      • getRows

        public List<List<Object>> getRows()
        Returns the same as the columns input option, but defining rows intead of columns.

        Default: null

      • setRows

        public void setRows​(List<List<Object>> rows)
        Sets the same as the columns input option, but defining rows intead of columns.

        Default: null

      • getRowsURL

        public String getRowsURL()
        Returns a URL to a remote JSON dataset, structured as a row array. Will be fetched when the chart is created using Ajax.

        Default: null

      • setRowsURL

        public void setRowsURL​(String rowsURL)
        Sets a URL to a remote JSON dataset, structured as a row array. Will be fetched when the chart is created using Ajax.

        Default: null

      • getStartColumn

        public Number getStartColumn()
        Returns in tabular input data, the first column (indexed by 0) to use.

        Default: 0

      • setStartColumn

        public void setStartColumn​(Number startColumn)
        Sets in tabular input data, the first column (indexed by 0) to use.

        Default: 0

      • getStartRow

        public Number getStartRow()
        Returns in tabular input data, the first row (indexed by 0) to use.

        Default: 0

      • setStartRow

        public void setStartRow​(Number startRow)
        Sets in tabular input data, the first row (indexed by 0) to use.

        Default: 0

      • isSwitchRowsAndColumns

        public boolean isSwitchRowsAndColumns()
        Returns switch rows and columns of the input data, so that this.columns effectively becomes the rows of the data set, and the rows are interpreted as series.

        Default: false

      • setSwitchRowsAndColumns

        public void setSwitchRowsAndColumns​(Boolean switchRowsAndColumns)
        Sets switch rows and columns of the input data, so that this.columns effectively becomes the rows of the data set, and the rows are interpreted as series.

        Default: false

      • getTable

        public String getTable()
        Returns an HTML table or the id of such to be parsed as input data. Related options are startRow, endRow, startColumn and endColumn to delimit what part of the table is used.

        Default: null

      • setTable

        public void setTable​(String table)
        Sets an HTML table or the id of such to be parsed as input data. Related options are startRow, endRow, startColumn and endColumn to delimit what part of the table is used.

        Default: null