Bars moving out x-axis - stacked-chart

enter image description hereenter image description hereAm using Echarts on this project .Everything works fine but my stacked bar charts arent working as expected after a scale rendering which increases the x-axis scale .The bars move out of the x-axis as indicated on the screenshot.
here is my code down here
$scope.$watch(attrs.eData, function (newValue, oldValue, scope) {
var legend = [],
sData = [],
data = newValue,
chartName = '';
series = newValue;
var totalSubtitle = 0;
angular.forEach(data, function (val) {
legend.push(val.name);
});
option = {
name: seriesName,
title: {
text: '',
subtext: totalSubtitle,
x: 'center'
},
tooltip: {
trigger: 'item',
axisPointer: {
type: 'shadow'
}
},
xAxis: {
type: 'value',
min: 0,
axisTick: {
show: true
},
axisTick: {
alignWithLabel: false
}
},
yAxis: {
type: 'category',
scale: true,
data: [seriesName],
max: 100,
min: 100,
axisTick: {
show: false
}
},
legend: {
orient: 'horizontal',
bottom: -29,
order: true,
data: legend
},
series: series
};
myChart.setOption(option);
}, true);
$scope.$watch(attrs.eOptions, function (newValue, oldValue) {
option.title.text = newValue.title.text;
option.title.subtext = newValue.title.subtext;
angular.forEach(newValue.series, function (val) {
seriesName = val.name;
});
myChart.setOption(option);
}, true);
myChart.on('click', function (params) {
$scope.SliceSelected(params);
});
$window.onresize = function () {
myChart.resize();
};
}
};

I got some points from your code this may help you out in this issue.
xAxis: {
type: 'value',
min: 0,
axisTick: {
show: true
},
axisTick: {
alignWithLabel: false
}
}
In the above mentioned code axisTick repeated two times
And change the "xAxis" type to "category" and "yAxis" type to "value".
Hope this will fix your issues

Related

c3.js reduce width of x-axis

is there a way to reduce the width of x-axis (see picture) in c3? Even if I tried to set "stroke-width" attribute to the "<"path">" tag with different values - it didn't make any visual changes. Thank you for your advices in advance.
Picture
var chart = c3.generate({
bindto: '#' + chartId,
data: {
columns: columns,
type: 'bar',
labels: true
},
interaction: {
enabled: false
},
tooltip: {
show: false
},
color: {
pattern: colorPattern
},
bar: {
width: { ratio: 0.7 },
space: 0.25
},
size: settings.ChartSizes.BarChart,
legend: {
position: 'right',
grouped: true,
item: {
onclick: function (d) {
counter++;
if (counter === 1) {
chart.hide();
chart.show(d);
} else {
chart.show();
counter = 0;
}
}
}
},
axis: {
x: {
type: 'category',
categories: categories,
show: showAxe
},
y: {
show: false
}
}
});
This is a common issue, caused by you not picking up the c3.css file - see https://github.com/c3js/c3/issues/1962
If you can fix that, the problem goes away

Populate three highchart graphics with one ajax call

I am trying to figure out how to combine 3 ajax call into 1 but so far I didn't find out the correct way to do it. I have the following three highcharts:
chart1 = new Highcharts.Chart({
chart: {
height: 155,
renderTo: 'chart1_div',
defaultSeriesType: 'spline',
events: {
load: GetData1(date)
}
},
plotOptions: {
series: {
fillOpacity: 0.1
}
},
xAxis: {
categories: c,
labels: {
staggerLines: 2
}
},
yAxis: {
gridLineColor: "#ffffcc",
title: {
text: ''
},
labels: {
x: 15,
y: 15,
style: {
color: "#999999",
//fontWeight: "bold",
fontSize: "10px"
}
},
},
series: [{
name: 'Chart1',
color: "#6bd9ec", //37f312
data: chart1_data
}]
});
chart2 = new Highcharts.Chart({
chart: {
height: 155,
renderTo: 'chart2_div',
defaultSeriesType: 'spline',
events: {
load: GetData2(date)
}
},
plotOptions: {
series: {
fillOpacity: 0.1
}
},
xAxis: {
categories: c,
labels: {
staggerLines: 2
}
},
yAxis: {
gridLineColor: "#ffffcc",
title: {
text: ''
},
labels: {
x: 15,
y: 15,
style: {
color: "#999999",
//fontWeight: "bold",
fontSize: "10px"
}
},
},
series: [{
name: 'Chart2',
color: "#6bd9ec", //37f312
data: chart2_data
}]
});
chart3 = new Highcharts.Chart({
chart: {
height: 155,
renderTo: 'chart3_div',
defaultSeriesType: 'spline',
events: {
load: GetData3(date)
}
},
plotOptions: {
series: {
fillOpacity: 0.1
}
},
xAxis: {
categories: c,
labels: {
staggerLines: 2
}
},
yAxis: {
gridLineColor: "#ffffcc",
title: {
text: ''
},
labels: {
x: 15,
y: 15,
style: {
color: "#999999",
//fontWeight: "bold",
fontSize: "10px"
}
},
},
series: [{
name: 'Chart3',
color: "#6bd9ec", //37f312
data: chart3_data
}]
});
At the moment I am making three different ajax calls:
function GetData1(date) {
$.ajax({
url: '/GetAjaxCall',
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ date: date }),
success: function (f) {
var cat= [];
var ser= [];
$.each(f.d, function (i, e) {
cat.push(e.date);
ser.push(parseInt(e.val1));
});
chart1_div.xAxis[0].setCategories(cat);
chart1_div.series[0].setData(ser);
},
error: function (e) {
alert(e.statusText);
},
cache: false
});
}
function GetData2(date) {
$.ajax({
url: '/GetAjaxCall',
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ date: date }),
success: function (f) {
var cat= [];
var ser= [];
$.each(f.d, function (i, e) {
cat.push(e.date);
ser.push(parseInt(e.val2));
});
chart2_div.xAxis[0].setCategories(cat);
chart2_div.series[0].setData(ser);
},
error: function (e) {
alert(e.statusText);
},
cache: false
});
}
function GetData3(date) {
$.ajax({
url: '/GetAjaxCall',
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ date: date }),
success: function (f) {
var cat= [];
var ser= [];
$.each(f.d, function (i, e) {
cat.push(e.date);
ser.push(parseInt(e.val3));
});
chart3_div.xAxis[0].setCategories(cat);
chart3_div.series[0].setData(ser);
},
error: function (e) {
alert(e.statusText);
},
cache: false
});
}
As you can see, I am right now making the same ajax call 3 times just to be able to populate the 3 charts differently. Does anyone know how could I generate exactly the same 3 charts but only make 1 ajax call? Thanks a lot
Something like:
function GetDataAll(date) {
$.ajax({
url: '/GetAjaxCall',
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ date: date }),
success: function (f) {
var cat1= [];
var ser1= [];
var cat2= [];
var ser2= [];
var cat3= [];
var ser3= [];
$.each(f.d, function (i, e) {
cat1.push(e.date);
ser1.push(parseInt(e.val1));
});
chart1_div.xAxis[0].setCategories(cat1);
chart1_div.series[0].setData(ser1);
chart2_div.xAxis[0].setCategories(cat2);
chart2_div.series[0].setData(ser2);
chart3_div.xAxis[0].setCategories(cat3);
chart3_div.series[0].setData(ser3);
},
error: function (e) {
alert(e.statusText);
},
cache: false
});
}
Under the load event I could call GetData1(date) for the 3 charts but this way I will be hitting the ajax call 3 times. I am probably doing this the wrong way and must be a more efficient way. I will appreciate any thoughts, thank you so much
EDITED - LATEST UPDATE THAT WORKS BASED ON #WERGELD HELP
var chart1_options = {
chart: {
renderTo: 'chart1_div',
xAxis: {
categories: []
},
series: [{
name: 'Chart1',
color: "#6bd9ec"
}]
};
var chart2_options = {
chart: {
renderTo: 'chart2_div',
xAxis: {
categories: []
},
series: [{
name: 'Chart2',
color: "#6bd9ec"
}]
};
var chart3_options = {
chart: {
renderTo: 'chart3_div',
xAxis: {
categories: []
},
series: [{
name: 'Chart3',
color: "#6bd9ec"
}]
};
function GetDataAll(date) {
$ajax({..
chart1_options.xAxis.categories = cat1;
chart1_options.series[0].data = ser1;
chart2_options.xAxis.categories = cat2;
chart2_options.series[0].data = ser2;
chart3_options.xAxis.categories = cat3;
chart3_options.series[0].data = ser3;
var chart1 = new Highcharts.Chart(Highcharts.merge(options, chart1_options));
var chart2 = new Highcharts.Chart(Highcharts.merge(options, chart2_options));
var chart3 = new Highcharts.Chart(Highcharts.merge(options, chart3_options));
});
}
Here is some psuedo code to get you going. What you need to do is setup a chart option object that contains all the constant items among your charts:
var options = {
chart: {
height: 155,
defaultSeriesType: 'spline'
},
plotOptions: {
series: {
fillOpacity: 0.1
}
},
xAxis: {
categories: c,
labels: {
staggerLines: 2
}
},
yAxis: {
gridLineColor: "#ffffcc",
title: {
text: ''
},
labels: {
x: 15,
y: 15,
style: {
color: "#999999",
//fontWeight: "bold",
fontSize: "10px"
}
},
}
};
Next you do your ajax call and assign your series' data and title (and any other items) and create an object for each chart you want to create:
var chartOptions1 = {
chart: { renderTo: 'container1' },
series: []
};
var chartOptions2 = {
chart: { renderTo: 'container1' },
series: []
};
Next you do your code to get the chart data/name/etc that you want to have for each chart which I will not go into here. The next step is to then create your chart from the merged options:
var chart1 = new Highcharts.Chart(Highcharts.merge(options, chartOptions1));
var chart2 = new Highcharts.Chart(Highcharts.merge(options, chartOptions2));
This should do it. Again, it is psuedocode but you get the idea. Global options + merge are you friends. Full psuedocode here.

How to get the datasource information from Kendo UI dragend event?

This is the code for the line chart which has drag function to highlight some data. I would like to get the datasource information in the dragEnd event,currently I am just getting screenX and screenY values.
function createChart(data) {
$("#TimeSeriesPlot").kendoChart({
title: {
text: series_name.toUpperCase()
},
dataSource :{
data:data.timeseries,
},
series: [{
type: "line",
field:"v",
categoryField:"ts",
}],
valueAxis: {
labels: {
format: "{0}"
},title:{
text: "value"
},
line: {
visible: false
},
},
categoryAxis: {
labels: {
type: "date",
},
tooltip: {
visible: true,
// shared:true,
template: "${category} - ${value}"
},
plotAreaClick: onPlotAreaClick,
seriesClick:onSeriesClick ,
dragStart:onDragStart ,
drag:onDrag,
dragEnd:onDragEnd
});
}
}
function onSeriesHover(e) {
console.log(kendo.format("Series hover :: {0} ({1}): {2}",
e.series.name, e.category, e.value));
}
function onSeriesClick(e){
// console.log(selected_anamolies);
// console.log(e.category);
selected_anamolies.push("ts",e.category);
selected_anamolies.push("v",e.value);
}
function onDragStart(e){
// console.log("dragstart"+e.axisRanges.ts);
// console.log("dragstart"+e.sender._highlight._points[0].value);
// console.log("dragstart"+e.sender._highlight._points[0].category);
}
function onDrag(e){
var Rect = kendo.geometry.Rect;
var draw = kendo.drawing;
prevloc=e.originalEvent.x.startLocation;
currentloc=e.originalEvent.x.location;
var rect=new Rect([prevloc,50],[currentloc-prevloc,150]);
var path = draw.Path.fromRect(rect,{ stroke: null,fill:{color:"#d3f1fb",opacity:0.2}});
var chart = e.sender;
// var surface = draw.Surface.create($("#surface"));
chart.surface.draw(path);
//
}
function onDragEnd(e){
console.log(dragEnd)
}

How to prevent the whole grid from refreshing when a single cell data changes in kendo grid?

While we can use virtualization or paging to speed up refreshing, the whole-grid refresh for each data change is not good at all. Is there a way to avoid this?
This gets worse when multiple data changes in the bound objects, the grid gets refreshed for each change, which is not good either.
function PresonDetails(_contactName, _contactTitle, _country, _companyName) {
Object.defineProperties(this, {
"ContactName": {
get: function () {
return this._contactName;
},
set: function (value) {
this._contactName = value;
},
enumerable: true,
configurable: true
},
"ContactTitle": {
get: function () {
return this._contactTitle;
},
set: function (value) {
this._contactTitle = value;
},
enumerable: true,
configurable: true
},
"Country": {
get: function () {
return this._country;
},
set: function (value) {
this._country = value;
},
enumerable: true,
configurable: true
},
"CompanyName": {
get: function () {
return this._companyName;
},
set: function (value) {
this._companyName = value;
},
enumerable: true,
configurable: true
}
});
this.ContactName = _contactName;
this.ContactTitle = _contactTitle;
this.Country = _country;
this.CompanyName = _companyName;
}
(function () {
var details = [];
details.push(new PresonDetails("ContactName1", "ContactTitle", "USA", "MICro"));
var refresh = window.kendo.ui.Grid.fn.refresh;
window.kendo.ui.Grid.fn.refresh = function () {
alert("Grid Refresh");
refresh.call(this,arguments);
}
var $grid = $('#grid');
$grid.kendoGrid({
scrollable: true,
dataSource: details,
groupable: false,
sortable: false,
editable: true,
columns: [{
field: "ContactName",
title: "Contact Name",
width: 200
}, {
field: "ContactTitle",
title: "Contact Title",
width: 250
}, {
field: "CompanyName",
title: "Company Name"
}, {
field: "Country",
width: 150,
}]
});
})();
here is the demo
Preventing the dataBinding event of the grid will stop the refresh:
funnction avoidRefresh(e) {
e.preventDefault();
}
// stop refresh
grid.bind("dataBinding", avoidRefresh);
// allow refresh
grid.unbind(avoidRefresh);

How to plot 500 points in a second in highchart?

We are supposed to plot 500 points every second from ajax request which we get it from WCF service(hosted in amazon cloud).
We are using highchart, but its very slow.
Is there any solution ? or any other graph control which we can use it in our case so that performnace is efficient
var chart = new Highcharts.Chart({
chart: {
type: 'spline',
animation: false,//Highcharts.svg, // don't animate in old IE
marginRight: 10,
renderTo: 'Chart',
events: {
load: function () {
}
}
},
title: {
text: 'Data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
max: ((new Date()).getTime()) + 50 * 10000
},
yAxis: {
title: {
text: 'Data',
min: 50,
max: 500
},
plotLines: [{
value: 0,
width: 1,
color: '#FFFF00'
}]
},
plotOptions: {
line: {
marker: {
enabled: false
}
}
},
tooltip: {
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
plotOptions: {
series: {
marker: {
enabled: false
}
}
},
series: [{
name: 'Chart',
color: '#335de8',
//data: []
data: (function () {
//generate an array of random data
var data = [];
var data = [],
time = (new Date()).getTime(), i;
for (i = 1; i <= 0; i++) {
data.push({
x: time + i * 1000,
y: null
});
}
return data;
})()
}]
});
chart.yAxis[0].setExtremes(-200, 500);
UpdateChart();
function UpdateChart() {
var Chrt = chart.series[0];
setInterval(function () {
$.ajax({
url: 'getChartData/',
cache: false,
type: "POST",
success: function (result) {
for (var tmpJ = 0; tmpJ < result.length; tmpJ++) {
Chrt.addPoint([(new Date()).getTime(), eval(result[tmpJ])], true, false);
Chrt.redraw(false);
}
});
}, 1000);
}
Try to replace this line
Chrt.addPoint([(new Date()).getTime(), eval(result[tmpJ])], true, false);
with
if(tmpJ==result.length-1){
Chrt.addPoint([(new Date()).getTime(), eval(result[tmpJ])], false, false);
} else {
Chrt.addPoint([(new Date()).getTime(), eval(result[tmpJ])], true, false);
}

Resources