jqplot - getting error while using multiple series with different renderers - jqplot

I have recently started using jqplot library for rendering graphs in our web app. I have downloaded version 1.0.8r1250. I am working with version 1.7 of jquery. I am trying to draw one bar graph and one line graph in the same canvas. Based on the documentation and the examples in the jqplot distribution, here is how I have configured it.
function drawGraph(data) {
$("#char1").empty();
$.jqplot.config.enablePlugins = true;
var lockinsByMarkup = [];
var lockinMarkupData = 'N/A':0, '<=10':16, '>10-20':15, '>20-30':1, '>30-40':0, '>40-50':3, '>50-60':10, '>60-70':0, '>70-80':12, '>80-90':0, '>90-100':0, '>100':0;
for (var prop_name in lockinMarkupData) {
lockinsByMarkup.push([prop_name, lockinMarkupData[prop_name]])
}
var recommendations = [1,2,3,4,5,6];
var plot1 = $.jqplot('chart1', [lockinsByMarkup, recommendations], {
// Only animate if we're not using excanvas (not in IE 7 or IE 8)..
animate: !$.jqplot.use_excanvas,
title: 'Current Customer Item Prices (CIP)',
axesDefaults: {
labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
tickOptions: {
showGridline: false
}
},
seriesDefaults:{
pointLabels: { show:true, hideZeros:true}
},
axes: {
xaxis: {
label:'Markup %',
renderer: $.jqplot.CategoryAxisRenderer,
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions: {
fontFamily: 'Georgia',
fontSize: '10pt',
angle: -30
}
},
yaxis: {
label: '# of CIP Records',
showTicks: false
}
},
series: [
{
renderer: $.jqplot.BarRenderer
},
{
renderer: $.jqplot.LineRenderer, // this is the default, but specifying just in case
showMarker: false,
showLine: false,
pointLabels: {labels: ['CFP', 'Min', 'Peer', 'Start', 'Default', 'Upper Limit']}
}
],
grid:{
drawBorder: true,
shadow: false
}
});
}
I have the following div on the page -
<div id="chart1" style="height:400px;width:500px; "></div> and I am executing the above function on the click of a button.
What is happening is, I am getting this error - Uncaught illegal access in jquery.jqplot.min.js.
If I just have one series, it is working fine. I have been struggling with error since yesterday afternoon. Can somebody please tell me what I am doing wrong?
I have included following js and css files on my page
jquery-1.7.min.js
jquery.jqplot.min.js
jqplot.barRenderer.min.js
jqplot.categoryAxisRenderer.min.js
jqplot.pointLabels.min.js
jqplot.canvasTextRenderer.min.js
jqplot.canvasAxisTickRenderer.min.js
jqplot.canvasAxisLabelRenderer.min.js
jquery.jqplot.min.css
Thanks for your help.

here is the solution: jsFiddle link
$(document).ready(function(){
function drawGraph(data) {
$("#chart1").empty();
$.jqplot.config.enablePlugins = true;
var lockinsByMarkup = [];
var recommendations = [];
var lockinMarkupData = {'N/A':0, '<=10':16, '>10-20':15, '>20-30':1, '>30-40':0, '>40-50':3, '>50-60':10, '>60-70':0, '>70-80':12, '>80-90':0, '>90-100':0, '>100':0};
for (var prop_name in lockinMarkupData) {
lockinsByMarkup.push([prop_name, lockinMarkupData[prop_name]]);
recommendations.push([prop_name, Math.round(Math.random()*10)]);
}
var plot1 = $.jqplot('chart1', [lockinsByMarkup, recommendations], {
// Only animate if we're not using excanvas (not in IE 7 or IE 8)..
animate: !$.jqplot.use_excanvas,
title: 'Current Customer Item Prices (CIP)',
axesDefaults: {
labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
tickOptions: {
showGridline: false
}
},
seriesDefaults:{
pointLabels: { show:true, hideZeros:true}
},
axes: {
xaxis: {
label:'Markup %',
renderer: $.jqplot.CategoryAxisRenderer,
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions: {
fontFamily: 'Georgia',
fontSize: '10pt',
angle: -30
}
},
yaxis: {
label: '# of CIP Records',
showTicks: false
}
},
series: [
{
renderer: $.jqplot.BarRenderer
},
{
renderer: $.jqplot.LineRenderer, // this is the default, but specifying just in case
showMarker: true,
showLine: true,
// pointLabels: {labels: ['CFP', 'Min', 'Peer', 'Start', 'Default', 'Upper Limit']}
}
],
grid:{
drawBorder: true,
shadow: false
}
});
}
drawGraph();
});

Related

How to show values on the bar vertically in apex bar chart

I am using apex bar chart in which i want to show values on the bar vertically but it shows horizontally.
I search alot to show value vertically but not find any solution. Please help me to solve this issue. I also share the code.
Here is The script of graph:
<script type="text/javascript">
$(document).ready(function() {
// custom datalabelBar
var options = {
chart: {
height: 350,
type: 'bar',
toolbar: {
show: true
}
},
plotOptions: {
bar: {
horizontal: false,
dataLabels: {
position: 'top',
},
}
},
dataLabels: {
enabled: true,
position: 'top',
formatter: function (val) {
return val ;
},
horizontal: true,
offsetX: 0,
style: {
fontSize: '10px',
colors: ['#000']
}
},
stroke: {
show: false,
width: 1,
colors: ['#fff'],
lineCap: 'round',
curve: 'smooth',
},
series: [{
name: 'Packing',
data: <?php echo json_encode($wd_packing) ?>
}, {
name: 'Dispatch',
data: <?php echo json_encode($wd_dispatch) ?>
},
{
name: 'Remaning',
data: <?php echo json_encode($wd_reaming) ?>
}],
xaxis: {
categories: <?php echo json_encode($wd_week) ?>,
},
}
var chart = new ApexCharts(
document.querySelector("#weekly_dispatch_graph"),
options
);
chart.render();
});
Here is the screenshot of graph:
Please Help me to solve this issue. Thanks in advance.
It is possible! Your question is about dataLabels. ApexCharts give us a common dataLabels option and a dataLabels option depended on chart type. There are options.dataLabels and options.plotOptions.bar.dataLabels respectively.
In the first one you can play with offsetY and in the second one you can configure this labels orientation and their position.
Try to play with this values, good luck :)
var options = {
chart: {
type: 'bar'
},
series: [{
name: 'Packing',
data: [300000, 300000, 500000, 800000]
}, {
name: 'Dispatch',
data: [46577, 296948, 153120, 0]
},
{
name: 'Remaning',
data: [252962, 2382, 235143, 800000]
}
],
xaxis: {
categories: ['Week 1', 'Week 2', 'Week 3', 'Week 4'],
},
plotOptions: {
bar: {
dataLabels: {
orientation: 'vertical',
position: 'center' // bottom/center/top
}
}
},
dataLabels: {
style: {
colors: ['#000000']
},
offsetY: 15, // play with this value
},
}
var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
<div id="chart"></div>
<script src="https://cdn.jsdelivr.net/npm/apexcharts#3.18.1/dist/apexcharts.min.js"></script>
dataLabels: {
position: 'top',
enabled: true,
textAnchor: 'start',
style: {
fontSize: '10pt',
colors: ['#000']
},
offsetX: 0,
horizontal: true,
dropShadow: {
enabled: false
}
},
Note the offsetX: 0 and horizontal: true.

set y axis values as zero for nonexisting x axis values in jqplot

I am using jqplot to create a graphic.
I have an issue about the nonexisting values.
I create a graphic with 5 lines as shown http://www.popularjava.net/wp-content/uploads/statisticGraphic.png
As you see from the picture, there is only one value for some lines such as orange line.
However, I would like to show such nonexisting values with y=0.
I mean, I want to put y=0 for all dates if there is no point for any date.
Here is my code.
var minGraphicXValue = response.minGraphicXValue;
var maxGraphicXValue = response.maxGraphicXValue;
var dataSeriesList = response.dataSeriesList;
var plot1 = $.jqplot('countGraphicGrid', response.countArray, {
title: 'Count/Time Graphic - ' + selectedItemType + ":" + itemValue + " - " + StatisticGraphic.selectedGraphicPeriod,
axes: {
xaxis: {
label: "Time",
labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
labelOptions: {
fontFamily: 'Helvetica',
fontSize: '14pt'
},
renderer: $.jqplot.DateAxisRenderer,
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions: {
formatString: StatisticGraphic.tickFormatPattern,
angle: -30
},
tickInterval: StatisticGraphic.tickIntervalTime,
min: minGraphicXValue,
max: maxGraphicXValue,
drawMajorGridlines: false
},
yaxis: {
label: "Count",
tickOptions: {
formatString: '%d'
},
min: 0,
max: 100,
autoscale: true
}
},
legend: {
show: true,
placement: 'outside'
},
seriesDefaults: {
rendererOptions: {
smooth: true,
animation: {
show: true
}
},
showMarker: true
},
series: dataSeriesList,
highlighter: {
show: true,
sizeAdjust: 7.5,
tooltipOffset: 9
},
grid: {
background: 'rgba(57,57,57,0.0)',
drawBorder: false,
shadow: false,
gridLineColor: '#666666',
gridLineWidth: 1
}
});
I think the best way to do it is to format your data before your render them on your plot.
I mean add values for your nonexisting ones. You can use your (min|max)GraphicXValue and set them to 0 if non existing.

jqplot: two y axis (decimal & percentage) for line chart

Is it possible for jqplot to have two y axis for one series in line chart: one for decimal values another for percentages?
Here is my code. There are two lines and their values are in percentages. I need to show two y-axis.
var irr1 = [['2008-09-30', -100], ['2008-10-30', -99.81], ['2008-11-30', -95.73],
['2008-12-30', -80.28], ['2009-01-30', -56.67], ['2009-02-28', -41.54],
['2009-03-30', -30.33], ['2009-04-30', -23.31], ['2009-05-30', -19.93],
['2009-06-30', -8.57], ['2009-07-30', 0.14], ['2009-08-30', 11.24], ['2009-09-30', 20.35]];
var irr2 = [['2008-09-30', -100], ['2008-10-30', -99.10], ['2008-11-30', -86.44], ['2008-12-30', -60.00], ['2009-01-30', -34.43],
['2009-02-28', -20.80], ['2009-03-30', -12.54], ['2009-04-30', -7.88], ['2009-05-30', -5.52],
['2009-06-30', -0.96], ['2009-07-30', 2.09], ['2009-08-30', 5.47], ['2009-09-30', 7.92]];
var data = [irr1, irr2];
var plot1 = $.jqplot(elem.attr('id'), data, {
animate: true,
grid: {
backgroundColor: "#FFFFFF",
gridLineColor: '#000000',
drawBorder: false,
shadow: false,
gridLineWidth: 0.5
},
//title: 'Default Date Axis',
seriesDefaults: {
rendererOptions: {
//////
// Turn on line smoothing. By default, a constrained cubic spline
// interpolation algorithm is used which will not overshoot or
// undershoot any data points.
//////
smooth: true
}
},
legend: {
renderer: $.jqplot.EnhancedLegendRenderer,
show: true,
location: 'n',
placement: 'outsideGrid',
//shrinkGrid: true,
rendererOptions: {
numberRows: 1
}
},
//legend: {
// renderer: $.jqplot.EnhancedLegendRenderer,
// show: true,
// rendererOptions: {
// numberRows: 1
// }
//},
axes: {
xaxis: {
renderer: $.jqplot.DateAxisRenderer,
tickOptions: { formatString: '%Y-%m-%d' },
min: '2008-09-01',
tickInterval: '1 month'
}
},
series: [{ lineWidth: 4, markerOptions: { style: 'square' } }],
series: [
{ label: 'IRR' },
{ label: 'MIRR' }
],
});

jqplot - Unwanted line at the left of the canvas

Does anyone see the problem in my code why this border apears?
I know that asking for the solution of a problem is not "best practice" but I have wasted some hours already and could not fix it...
I'm sure its just a simple config problem I just can not see but someone with more practice in jqplot can find in a few seconds...
Here is the code I'm using:
jQuery.jqplot(this.getNonHasheContainerName(), chartDrawingData, {
animate: false,
seriesColors: barChartColors,
seriesDefaults: barChartSeriesDefaults,
grid: ChartGridDefaults,
series: this.getBarChartSeriesLabels(chartMetadata.series),
legend: barChartLegendDefaults,
title: { show: false },
axes: barChartAxisDefaults(ticks, chartMetadata.showGrid)
});
var barChartColors = ['#9FC0DF', '#EFAD81'];
var barChartSeriesDefaults = {
renderer: jQuery.jqplot.BarRenderer,
rendererOptions: {
barMargin: 10,
highlightMouseOver: true,
animation:
{
speed: 2500
}
},
pointLabels: { show: true },
shadow: false
};
var barChartLegendDefaults = {
show: true,
location: 'e',
placement: 'outsideGrid'
};
var barChartAxisDefaults = function (ticks, showGrid) {
return {
xaxis: {
show: false,
renderer: jQuery.jqplot.CategoryAxisRenderer,
tickRenderer: jQuery.jqplot.CanvasAxisTickRenderer,
ticks: ticks,
tickOptions: {
angle: 45,
fontSize: "11px",
showGridline: false,
showMark: true,
//labelPosition: 'end',
mark: 'inside',
markSize: 10
},
},
yaxis: {
show: false,
min: 0,
tickOptions: {
showMark: false,// showGrid,
showLabel: false,// showGrid,
showGridline: false,
tickInterval: 1,
formatString: '%d',
//borderWidth: 1
},
},
x2axis: {
show: false
},
y2axis: {
show: false
}
};
};
var ChartGridDefaults = {
shadow: false,
background: '#ffffff',
borderWidth: 1,
drawGridlines: false,
drawBorder: false
};
var pieChartSeriesDefaults = {
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
showDataLabels: true,
dataLabels: 'value',
fill: true,
sliceMargin: 2,
lineWidth: 5
},
shadow: false
};
var pieChartLegendDefaults = {
show: true,
location: 'e'
};
I HAVE GOT IT!!!
There is an other hidden (or i have overseen it in the documentation...) setting for the renderer:
yaxis: {
show: false,
min: 0,
tickOptions: {
showMark: false,// showGrid,
showLabel: false,// showGrid,
showGridline: false,
tickInterval: 1,
formatString: '%d',
},
**rendererOptions: {
drawBaseline: false
}**
}

Want pie chat without percentage slice

I want a pie chat using jqplot which will show the exact number (not percentage) inside each slice of pie chat.
$(document).ready(function(){
var s1 = [['Sony',200], ['Samsumg',40]];
var plot8 = $.jqplot('chart1', [s1], {
seriesColors: [ "#533E6A","#B4150C"],
grid: {
drawBorder: false,
drawGridlines: false,
background: '#ffffff',
shadow:false
},
axesDefaults: {
},
seriesDefaults:{
renderer:$.jqplot.PieRenderer,
rendererOptions: {
showDataLabels: true,
// sliceMargin: 2,
startAngle: -90
// diameter:30
}
},
legend: {
// show: false,
rendererOptions: {
numberRows: 1
},
location: 's'
}
});
});
Below is the jsfiddle(http://jsfiddle.net/JWhmQ/2032/) but it is showing the slice in percentage..instead i want the actual number(like 200 and 40).
You need to add
dataLabels='value'
, in the rendererOptions, as described here. I fixed your jsfiddle here.

Resources