Highcharts and EXTJS 3: Labels in x axis overlap - javascript
I am trying to implement a Highchart line graph with a datetime x axis on an EXTJS 3 panel so I am using extjs adapter and all the stuff provided on Sencha forums.
I am facing a very weird problem. All tick labels on my x axis are in the same position so they overlap, as seen here:
Here is the code I am working with:
var store = new Ext.data.JsonStore({
url: '/graph',
fields: [
{name: 'datamesura', type: 'int'},
{name: 'despl_hor', type: 'float'},
{name: 'despl_ver', type: 'float'}
],
root: 'dades'
});
var datastore_task = {
run: function() {
store.load();
}
};
Ext.TaskMgr.start(datastore_task);
Ext.QuickTips.init();
var chart;
chart = new Ext.ux.HighChart({
series: [{
type: 'spline',
dataIndex: 'despl_hor',
name: 'Desplaçament horitzontal'
},{
type: 'spline',
dataIndex: 'despl_ver',
name: 'Desplaçament vertical'
}],
height: 500,
width: 700,
store: store,
animShift: true,
xField: 'datamesura',
chartConfig: {
chart: {
marginRight: 210,
marginBottom: 120,
zoomType: 'xy'
},
toolbar: {
itemStyle: {
color: '#4572A7',
cursor: 'pointer'
},
layout: {
xPosition: 'right',
yPosition: 'top',
x: 0,
y: -10
}
},
title: {
text: 'Prismes',
x: -20
},
subtitle: {
text: 'Desplaçament',
x: -20
},
xAxis: [{
title: {
text: 'Data',
margin: 20
},
labels: {
rotation: 270,
y: 35
},
type: 'datetime'
}],
yAxis: [{
title: {
text: 'Valor'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
}],
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: 0,
y: 100,
borderWidth: 0
}
}
});
new Ext.Window({
title: 'Example',
layout: 'anchor',
items: [chart]
}).show();
Graph and time scale are being rendered properly. Even dates are correct in tooltips when I rollover any point. But as you see, all labels are in the beginning of x axis.
Data is coming from a JSON file in a format like this:
{"dades":[{"datamesura":1305158400000,"despl_hor":0,"despl_ver":0},{"datamesura":1305590400000,"despl_hor":0.85509233483876,"despl_ver":0.7406906575},{"datamesura":1305763200000,"despl_hor":0.40065251939804,"despl_ver":0.3806685951},{"datamesura":1306195200000,"despl_hor":1.3354238226121,"despl_ver":0.3883164125},{"datamesura":1306368000000,"despl_hor":1.2300886025811,"despl_ver":0.3028934962},{"datamesura":1306800000000,"despl_hor":0.76491207579695,"despl_ver":0.7382504417},{"datamesura":1306972800000,"despl_hor":0.97067811781249,"despl_ver":0.3934538156},{"datamesura":1307404800000,"despl_hor":0.99251776941272,"despl_ver":0.1344402012},{"datamesura":1307577600000,"despl_hor":1.7576987265171,"despl_ver":-0.0731718418},{"datamesura":1308009600000,"despl_hor":1.7982043839063,"despl_ver":0.8377618489},{"datamesura":1308182400000,"despl_hor":1.6815243145135,"despl_ver":0.6510250418},{"datamesura":1308614400000,"despl_hor":1.4625103263909,"despl_ver":0.2423211682},{"datamesura":1308787200000,"despl_hor":1.059558961408,"despl_ver":0.9443423224},{"datamesura":1309219200000,"despl_hor":1.8495061606277,"despl_ver":0.7814450066},{"datamesura":1309392000000,"despl_hor":1.9162507008479,"despl_ver":0.6051177109},{"datamesura":1309824000000,"despl_hor":1.7213552221723,"despl_ver":0.6680561831},{"datamesura":1309996800000,"despl_hor":1.9444381633778,"despl_ver":0.8635180524},{"datamesura":1310428800000,"despl_hor":1.6798176421267,"despl_ver":0.8274643529},{"datamesura":1310601600000,"despl_hor":1.4467543786006,"despl_ver":0.4695790538},{"datamesura":1311033600000,"despl_hor":1.4726130928727,"despl_ver":0.2477731064},{"datamesura":1311206400000,"despl_hor":1.2836033705939,"despl_ver":0.2656530857},{"datamesura":1311638400000,"despl_hor":1.5078416389993,"despl_ver":0.3320340535},{"datamesura":1312243200000,"despl_hor":1.9332533948761,"despl_ver":0.9397637894},{"datamesura":1312848000000,"despl_hor":1.2659382917425,"despl_ver":0.0425702553},{"datamesura":1313452800000,"despl_hor":1.2477477249428,"despl_ver":0.8257942379},{"datamesura":1314057600000,"despl_hor":1.8118509156661,"despl_ver":0.4792052981},{"datamesura":1314662400000,"despl_hor":1.918020654138,"despl_ver":0.5906438039},{"datamesura":1315267200000,"despl_hor":1.7023765324099,"despl_ver":0.8507942294},{"datamesura":1315872000000,"despl_hor":1.973909305414,"despl_ver":0.9492018485},{"datamesura":1316476800000,"despl_hor":1.932831196975,"despl_ver":0.8957622496},{"datamesura":1317081600000,"despl_hor":1.8232818443949,"despl_ver":1.0017163985},{"datamesura":1317686400000,"despl_hor":0.73874846050601,"despl_ver":0.5016692077},{"datamesura":1318896000000,"despl_hor":0.98500785814124,"despl_ver":0.2459143327},{"datamesura":1320192000000,"despl_hor":1.8171299009977,"despl_ver":0.695824387},{"datamesura":1321401600000,"despl_hor":1.0247267158126,"despl_ver":0.9220291425},{"datamesura":1322524800000,"despl_hor":1.7464007827529,"despl_ver":0.7178103147},{"datamesura":1323734400000,"despl_hor":1.8637498241985,"despl_ver":0.7515986697}]}
Does anyone have a clue? I am about to give up and try another charting library even though I like Highcharts very much.
This seems like an issue w/the span of the x-axis. I'm not at all familiar w/the ExtJS adapter but I would suggest looking into any of these:
Could your options be pointing to the wrong field?
Using the series.pointStart/series.pointInterval controls
Using the xAxis setExtremes controls
Related
xAxis label category overlay when use break in higchart
When I use xAxis categories with breaks the label of xAxis, overlay like the example below. Does it have a solution? A way to stop the overlay. Is there a way to use breaks with xAxis.categories? Example: Breaks bug var chart = new Highcharts.Chart({ chart: { renderTo: 'container', alignTicks:false, zoomType: 'xy', resetZoomButton: { position: { align: 'left', verticalAlign: 'top', x: 10, y: 10 }, relativeTo: 'chart' }, }, xAxis: { categories: ["2022-06-06","2022-06-07","2022-06-08","2022-06-09","2022-06-10","2022-06-11","2022-06-12","2022-06-13"], breaks:[{ from:2, to:3 }] }, yAxis:{ title:{ text : '%' }, max: 100, }, series: [{ color: "#e88307", type: "spline", data: [99.68,99.69,99.68,99.62,99.62,99.59,99.57,99.67] },{ color: "#9d07e8", type: "spline", data: [99.89,99.89,99.89,99.88,99.88,99.88,99.88,99.89] },{ color: "#0738e8", type: "spline", data: [98.86,98.85,98.94,98.55,97.42,96.75,96.79,96.46] },{ color: "#07e838", type: "spline", data: [98.4352499872,98.4351670785,98.5149062688,98.057699388,96.9333442352,96.23770101,96.2581544364,96.0359261498] }] });
Responsive rules should work here to change way of show labels, you can use xAxis.labels.rotation, xAxis.labels.step or xAxis.labels.staggerLines. responsive: { rules: [{ condition: { maxWidth: 1000 }, chartOptions: { xAxis: { labels: { rotation: -45, } } } }] } Demo: https://jsfiddle.net/BlackLabel/2kzx6n3r/
EXTJS 5 chart disappears just after displaying
I am trying to add a chart to a panel. However the chart disappears right after rendering (I can see it for like 1 sec). The title still remains but everything else is gone (legend included) Ext.define('MyProject.view.FoodDetail', { extend: 'Ext.panel.Panel', layout: { type: 'vbox', align: 'stretch' }, items: [{ flex: 1, xtype: 'panel', // width: '100%', height: 350, reference: 'pieContainer' } ] }) Then in the controller I add the pie chart to the pieContainer like this (similarly to the Kitchen Sink example) setPie: function (myStore) { var chartContainer = this.lookupReference('pieContainer') chartContainer.add({ xtype: 'polar', height: 350, store: arrayStore, insetPadding: 50, innerPadding: 20, reference: 'foodPieChart', legend: { docked: 'bottom' }, interactions: ['rotate', 'itemhighlight'], sprites: [ { type: 'text', text: 'Food composition', font: '22px Helvetica', width: 100, height: 30, x: 40, // the sprite x position y: 20 // the sprite y position } ], series: [{ type: 'pie', angleField: 'amount', label: { field: 'category', display: 'outside', calloutLine: { length: 60, width: 3 // specifying 'color' is also possible here } }, highlight: true, tooltip: { trackMouse: true, renderer: function (storeItem, item) { this.setHtml(storeItem.get('category') + ': ' + storeItem.get('amount')) } } }] }) } I have tried playing around with the renderTo and other things but I can't seem to figure out what is happening.
hightChart print 'noData' message
I use the library hightChart for build some graph and i want to put a message when their is no data in my chart so i have this javascript code : statChart = new Highcharts.Chart ({ lang: { noData : "no data", }, chart: { renderTo: 'chart_container', type: 'line', marginRight: 130, marginBottom: 25 }, title: { text: 'Graphique', x: -20 }, subtitle: { x: -20 }, xAxis: { categories:['Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Décembre', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai'] }, yAxis: { title: { text: '' }, plotLines: [{ value: 0, width: 1, color: '#808080' }] }, legend: { layout: 'vertical', align: 'right', verticalAlign: 'top', x: -10, y: 100, borderWidth: 0, }, credits : { enabled : false } }); And after i add some data with javascript like that : newSerie = statChart.addSeries( { name : nameGraph, data : [] }); But i never arrive to print the message who say no data and i really don't understand why because on all the exemple i find their is nothing special to do for print this message.
you need also include the no-data-to-display.js:http://code.highcharts.com/modules/no-data-to-display.js
Column width in Highcharts when combined with spline
I have this annoying thing in Highcharts that I cannot figure out. I have graphs that are dynamically generated and can contain multiple columns and splines. In the example the spline is a temperature measurement and contains lots of data points. The two columns are grouped by day and therefore contain only one value per day. When I use this combination the column width becomes almost invisible: http://jsfiddle.net/FXRj2/ $(function () { $('#container').highcharts({ chart: { zoomType: 'xy' }, title: { text: 'Test' }, subtitle: { text: 'Me' }, xAxis: [{ type: 'datetime' }], yAxis: [{ // Primary yAxis labels: { format: '{value}°C', style: { color: '#89A54E' } }, title: { text: 'Temperature', style: { color: '#89A54E' } } }, { // Secondary yAxis title: { text: 'Rainfall 2', style: { color: '#4572A7' } }, labels: { format: '{value} mm', style: { color: '#4572A7' } }, opposite: true }, { // Tertiary yAxis title: { text: 'Rainfall 2', style: { color: '#red' } }, labels: { format: '{value} mm', style: { color: '#4red' } }, opposite: true }], tooltip: { shared: true }, legend: { layout: 'vertical', align: 'left', x: 120, verticalAlign: 'top', y: 100, floating: true, backgroundColor: '#FFFFFF' }, series: [{ name: 'Rainfall 1', color: '#4572A7', type: 'column', yAxis: 1, data: [[1374105600000,1461.77],[1374192000000,1473.67],[1374278400000,1122.47],[1374364800000,1170.16],[1374451200000,1436.88],[1374537600000,1383.57],[1374624000000,9.73]], tooltip: { valueSuffix: ' mm' } }, { name: 'Rainfall 2', color: '#red', type: 'column', yAxis: 2, data: [ [1374105600000,3.28],[1374192000000,2.95],[1374278400000,3.12],[1374364800000,3.8],[1374451200000,3.61],[1374537600000,0.39]], tooltip: { valueSuffix: ' mm' } }, { name: 'Temperature', color: '#89A54E', type: 'spline', data: [[1374105600000,21.9],[1374109200000,21.6],[1374112800000,21.2],[1374116400000,20.8],[1374120000000,20.5],[1374123600000,20],[1374127200000,19.7],[1374130800000,19.6],[1374134400000,19.9],[1374138000000,20.3],[1374141600000,20.9],[1374145200000,21.4],[1374148800000,21.9],[1374152400000,22.5],[1374156000000,23.1],[1374159600000,23.5],[1374163200000,23.9],[1374166800000,23.7],[1374170400000,23.8],[1374174000000,23.3],[1374177600000,23.1],[1374181200000,22.4],[1374184800000,21.9],[1374188400000,21.4],[1374192000000,21],[1374195600000,20.4],[1374199200000,20.1],[1374202800000,19.7],[1374206400000,19.3],[1374210000000,19],[1374213600000,18.7],[1374217200000,18.9],[1374220800000,19.3],[1374224400000,19.8],[1374228000000,20.6],[1374231600000,21.4],[1374235200000,22.1],[1374238800000,22.6],[1374242400000,23.2],[1374246000000,23.5],[1374249600000,23.5],[1374253200000,23.5],[1374256800000,23.1],[1374260400000,23],[1374264000000,22.4],[1374267600000,22],[1374271200000,21.4],[1374274800000,21.2],[1374278400000,20.6],[1374282000000,20.2],[1374285600000,20.3],[1374289200000,20.2],[1374292800000,20],[1374296400000,19.7],[1374300000000,19.3],[1374303600000,19],[1374307200000,18.9],[1374310800000,19],[1374314400000,19.2],[1374318000000,19],[1374321600000,19.7],[1374325200000,19.8],[1374328800000,20.2],[1374332400000,20.6],[1374336000000,21],[1374339600000,21.6],[1374343200000,21.8],[1374346800000,22.1],[1374350400000,22.3],[1374354000000,22.1],[1374357600000,21.5],[1374361200000,21.1],[1374364800000,20.6],[1374368400000,20.1],[1374372000000,19.7],[1374375600000,19.4],[1374379200000,19],[1374382800000,18.6],[1374386400000,18.2],[1374390000000,18.2],[1374393600000,18.6],[1374397200000,19.4],[1374400800000,20.4],[1374404400000,21.6],[1374408000000,22.9],[1374411600000,24.2],[1374415200000,25.4],[1374418800000,26.5],[1374422400000,27.2],[1374426000000,27.8],[1374429600000,28.3],[1374433200000,28.5],[1374436800000,28.4],[1374440400000,27.8],[1374444000000,27.1],[1374447600000,26.2],[1374451200000,25.7],[1374454800000,25],[1374458400000,24.3],[1374462000000,23.8],[1374465600000,23.1],[1374469200000,22.5],[1374472800000,22.1],[1374476400000,22.2],[1374480000000,22.5],[1374483600000,23.1],[1374487200000,23.9],[1374490800000,24.9],[1374494400000,26.1],[1374498000000,27],[1374501600000,27.8],[1374505200000,28.4],[1374508800000,28.9],[1374512400000,29.1],[1374516000000,29.2],[1374519600000,29],[1374523200000,28.7],[1374526800000,28.5],[1374530400000,27.7],[1374534000000,27.3],[1374537600000,26.8],[1374541200000,26.5],[1374544800000,25.9],[1374548400000,25.4],[1374552000000,24.8],[1374555600000,24.1],[1374559200000,23.6],[1374562800000,23.5],[1374566400000,23.8],[1374570000000,24.3],[1374573600000,24.9],[1374577200000,25.5],[1374580800000,25.7],[1374584400000,26.3],[1374588000000,27.3],[1374591600000,28.1],[1374595200000,28.5],[1374598800000,28.9],[1374602400000,29],[1374606000000,29.4],[1374609600000,29.1],[1374613200000,28.9],[1374616800000,28.2],[1374620400000,27.6],[1374624000000,26.9],[1374627600000,26.2],[1374631200000,25.6],[1374634800000,25.1],[1374638400000,24.6],[1374642000000,24.3],[1374645600000,23.7],[1374649200000,23.6],[1374652800000,23.5],[1374656400000,23.9],[1374660000000,24.4],[1374663600000,24.4],[1374667200000,24.3],[1374670800000,24.9],[1374674400000,25.9],[1374678000000,26.3]], tooltip: { valueSuffix: '°C' } }] }); }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div> I have been searching for ways to dynamically control the width of columns by using pointWidth but this gets me into a hole new area of issues, as I am not always sure if there is a combination of columns and splines and what the date range is. Is there a trick to solve this? I hope I have missed something simple.
I was reading through the API description of Highcharts when I noticed an option to have multiple x axis. Since my problem seemed to be related to scaling on the x axis I decided to give it a go... I created a new x axis for the line data and it works like a charm. Of course we do not want to see multiple x axis, so a little fiddling with the settings hides it again. My x axis definition now looks like this: xAxis: [{ type: 'datetime', },{ type: 'datetime', lineWidth: 0, minorGridLineWidth: 0, lineColor: 'transparent', opposite: true, labels: { enabled: false }, minorTickLength: 0, tickLength: 0 }], On the data series that has 'too many' points I simply added 'xAxis: 1'. Fiddle here : http://jsfiddle.net/AM4vx/
Customizing the colors of individual series in HighCharts
I am using HighCharts for a line graph and i am attemping to change the line color for each series. I did find this example here but the data is hard coded. My data is pulled from an Sql database and passed to the HTML page using some VB code. var chart; $(document).ready(function () { chart = new Highcharts.Chart({ chart: { renderTo: 'container', defaultSeriesType: 'column' }, title: { text: 'Chart Title' }, subtitle: { text: 'Chart subtitle' }, xAxis: { categories: [<%= GraphDate %>] , labels: { rotation: -45, align: 'right', style: { } } }, yAxis: { min: 160, title: { text: 'Temp' } }, legend: { layout: 'vertical', backgroundColor: '#FFFFFF', align: 'left', verticalAlign: 'top', x: 400, y: 0, floating: true, shadow: true }, tooltip: { formatter: function () { return '' + this.x + ': ' + this.y + ' ºC'; } }, plotOptions: { column: { pointPadding: 0.2, borderWidth: 0 } }, series: [<%= GraphSeries %>], }); I tried to style it using the other post however it failed to generate a chart. The main problem is though, the line graph has two series, so the below method would set the color for both series i assume? So, would i maybe need to format the series in my vb code somehow? series: [{ color: 'yellow', data: [ [<%= GraphSeries %>] ]}, Edit: $(document).ready(function () { chart = new Highcharts.Chart({ colors: ['#4572A7', '#AA4643', '#89A54E', '#80699B', '#3D96AE', '#DB843D', '#92A8CD', '#A47D7C', '#B5CA92'] chart: { renderTo: 'container', defaultSeriesType: 'column' }
Top level config can contain colors field. It's an array from which series colors will be picked. See here. Here's working piece from my project var chart; $(document).ready(function () { chart = new Highcharts.Chart({ chart:{ renderTo:'perfchart', type:'line', marginRight:130, marginBottom:25 }, colors: ['#0000FF', '#0066FF', '#00CCFF'], title:{ text:'Historical system performance', x:-20 //center }, Appearance:
See the code (and the plot that it renders) below. The snippet below is a complete script--i.e., either put it in your markup between two script tags or as a stand-along js file with an includes in your markup. Colors is a Chart object so the easiest way is to pass an array of colors (as hex strings): $(function () { var chart; $(document).ready(function() { chart = new Highcharts.Chart({ chart: { renderTo: 'container', type: 'line' }, colors: ['#562F1E', '#AF7F24', '#263249', '#5F7F90', '#D9CDB6'], title: { text: false }, yAxis: { title: { text: false } }, series: [{ name: 'series I', data: [17.4, 16.1, 19.45, 24.15, 28.44, 33.15, 37.2, 41.25, 43.3] }, { name: 'series II', data: [13.19, 17.23, 25.74, 28.5, 33.9, 35.62, 37.0, 36.6, 34.82] } ] }); }); })
The color can be configured as part of the series. Try something like this: series: [ { name: 'series I', color: '#ffffff', data: [17.4, 16.1, 19.45, 24.15, 28.44, 33.15, 37.2, 41.25, 43.3] } ];