1
votes

I am using jqplot to create a pie chart from an HTML table.

However, when attempting to set a var the chart doesn't plot.

If i simply set a number for the var, such as:

var DataTest = 22;

then the chart works fine.

However, when I get the value from the table it doesn't, as below:

var DataTest = $(dataID + ' td:nth-child(46)').text();

The pie chart wont display.

The pie chart series is being set through a var also:

var PieChartS1 = [ ['Label', DataTest] ];

Then included in the chart code as follows:

 var PieChartPlot = $.jqplot('PieChart', [PieChartS1, PieChartS2 ], {
 seriesDefaults: {
    renderer:$.jqplot.DonutRenderer,
    rendererOptions:{
    sliceMargin: 1,
    startAngle: -145,
    showDataLabels: true,
    dataLabels: 'label',
    padding: '5',
    ringMargin: '5',
    dataLabelThreshold: '1',
    highlightMouseOver: true,
  }   
},
grid: {background: 'transparent', borderWidth: '0', cursor: 'pointer',},

});

I'm wondering whether it is a format issue?

Thanks for any help

Richard

Update:

Am wondering whether the graph is being formed by the script before the data has been obtained, so it is just showing blank as it is finding no data. Perhaps I need to delay the graph formation until the 'get data' scripts are fully executed?

1
I have draw up a JSFiddle jsfiddle.net/6x82om3x/3 The inner donut that has the test script is showing, which it isn't on my site. However, you can clearly see that it is not displaying the data properly and the labels aren't displaying either. the first button uses specified values, the second button uses an example of this code to get the value from the table in the inner donut. There is also no error in the error reporting in chrome. - Richard Harris

1 Answers

0
votes

Had some help from elsewhere.

It needs to be specified as an integer, so the change needs to be:

var DataTest = parseInt($(dataID + ' td:nth-child(46)').text());

This works fine.