jQWidgets Forums

jQuery UI Widgets Forums Chart variable source + data extraction

This topic contains 3 replies, has 1 voice, and was last updated by  mim 7 years, 9 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • variable source + data extraction #95445

    mim
    Participant

    Hi,
    in order to plot a multichart applicable data need to be accessible in right format…mine are:

    eg.
    [{“sensor1”:[{“Date”:”2017-08-01″,”Counter”:”12″}]},{“sensor2”:[{“Date”:”2017-08-01″,”Counter”:”12″},{“Date”:”2017-08-05″,”Counter”:”12″}]}]

    data is fetched via mysql query and feeded into jquery well-known like this:

    
     $(document).ready(function () {
    			
      var source =	
         {
    	datatype: "json",
    	url: 'data.php'
         };		
     });
    

    Now, I want to work on var source to define following variables, represeting individual data source for each line in tghe multiline chart to be defined:

    
    var sensor1 = [{"Date":"2017-08-01","Counter":"12"}]
    var sensor2 = [{"Date":"2017-08-01","Counter":"12"},{"Date":"2017-08-05","Counter":"12"}]
    

    multiline chart definition should look like (example, incomplete)
    `
    seriesGroups:
    [
    {
    type: ‘line’,
    source: sensor1,
    series: [
    { dataField: ‘Counter’, displayText: ‘Counter’ }
    ]
    },
    {
    type: ‘line’,
    source: sensor2,
    series: [
    { dataField: ‘Counter’, displayText: ‘Counter’ }
    ]
    },
    ]

    Any advice?
    Kr, Michael

    variable source + data extraction #95446

    mim
    Participant

    …just did some search in the forum and stumbled across:

    
     $(document).ready(function () {
    			
    			
    			var source =
    			{
    				datatype: "json",
    				url: 'data4.php'
    			};		
    			
    		   <strong>var adapter = new $.jqx.dataAdapter(source);
       	           adapter.dataBind();
    	           console.log(adapter);</strong>          
          	});
    

    This shows me that within recordsid are the data I am striving for!
    But I do not know to access them, respectively to get get them assigned to another variable…an console.log(adapter.recordids) causes an empty array…

    a.jqx.dataAdapter {_source: {…}, _options: {…}, records: Array(0), _downloadComplete: Array(0), _bindingUpdate: Array(0), …}

    —–snip——-
    recordids
    :
    Array(6)
    0
    :
    {sensor1: “12”, Date: “2017-08-01”}
    1
    :
    {sensor1: “12”, Date: “2017-08-05”}
    2
    :
    {sensor1: “30”, Date: “2017-08-05”}
    3
    :
    {sensor2: “12”, Date: “2017-08-01”}
    4
    :
    {sensor2: “12”, Date: “2017-08-05”}
    5
    :
    {sensor2: “30”, Date: “2017-08-05”

    ——-snip——-

    variable source + data extraction #95448

    mim
    Participant

    again…some adaptations:

    delivered json format:
    data3.php: [{"Sensor":"test","Date":"2017-08-01","Counter":"12"},{"Sensor":"test","Date":"2017-08-05","Counter":"12"}]

    code that prepares data for charting:

    var sensorData = [];
    var sDataAdapter = new $.jqx.dataAdapter(source, {
              loadComplete: function() {
                  var records= sDataAdapter.records;
                  for (var i = 0; i < records.length; i++) {
                         sensorData.push( { [records[i]['Sensor']]:records[i]['Counter'], 'Date':records[i]['Date']} );
                   }             		         
     });

    sensorData: [{“current”:”12″,”Date”:”2017-08-01″},{“water”:”30″,”Date”:”2017-08-05″}

    Now, there is a problem when charting as no lines are drawn!

    code in use:
    `var settings = {
    title: “TEST”,
    showLegend: true,
    source: sensorData,
    xAxis:
    {
    dataField: ‘Date’
    },
    colorScheme: ‘scheme02’,
    seriesGroups:
    [
    {
    type: ‘stackedline’,
    source: sensorData,
    series: [
    { dataField: ‘water’, displayText: ‘Water’}
    ]
    {
    type: ‘stackedline’,
    source: sensorData,
    series: [
    { dataField: ‘current’, displayText: ‘Current’}
    ]
    }

    ]
    };

    // setup the chart
    $(‘#chartContainer’).jqxChart(settings);

    variable source + data extraction #95451

    mim
    Participant

    issue solved meanwhile;

    A) data appropriate prepared at data extraction from sql db
    B) that resolved the charting issue, too

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.