HighMap displaying issue with customized json file - javascript
I am trying to load json file with three variables into HighMap.
In my revised JSON I included three columns:
1. Code 2. Value 3. Median Wage
I was able to load JSON file through main.js, but with Median Wage added, the map lost its gradient and I was not able to start a new line for Median Wage in the hover-over displaying box.
The demo from HighCharts looks like this:
http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/maps/demo/color-axis/
Any input will be much appreciated.
Thank you!
HTM File
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highmaps Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
${demo.css}
</style>
</head>
<body>
<script src="js/main.js"></script>
<script src="js/highmaps.js"></script>
<script src="http://code.highcharts.com/mapdata/countries/us/us-all.js"></script>
<script src="js/modules/data.js"></script>
<div id="container" style="height: 500px; min-width: 310px; max-width: 600px; margin: 0 auto"></div>
</body>
</html>
Main js
function create_chart() {
$.getJSON('data.json', function (data) {
// Make codes uppercase to match the map data
$.each(data, function () {
this.Code = this.Code.toUpperCase();
});
console.log(data);
// Instanciate the map
$('#container').highcharts('Map', {
chart : {
borderWidth : 1
},
title : {
text : 'US Density vs Median Wage'
},
legend: {
layout: 'horizontal',
borderWidth: 0,
backgroundColor: 'rgba(255,255,255,0.85)',
floating: true,
verticalAlign: 'top',
y: 25
},
mapNavigation: {
enabled: true
},
colorAxis: {
min: 1,
type: 'logarithmic',
minColor: '#eefff1',
maxColor: '#000022',
stops: [[0, '#effff5'],
[0.67, '#61ae0e'],
[1, '#000022']]
},
series : [{
animation: {
duration: 1000
},
data : data,
mapData: Highcharts.maps['countries/us/us-all'],
joinBy: ['postal-code','Code'],
dataLabels: {
enabled: true,
color: 'white',
format: '{point.Code}'
},
name: 'US Density vs Median Wage',
tooltip: {
pointFormat: '{point.Code}: {point.Value}% \n Median Wage: ${point.MedianW}'
}
}]
});
});
}
$(document).ready(create_chart);
json file
[
{
"Code":"AL",
"Value":11.8,
"MedianW":40120
},
{
"Code":"AK",
"Value":24.5,
"MedianW":53804
},
{
"Code":"AZ",
"Value":6,
"MedianW":42107
},
{
"Code":"AR",
"Value":4.1,
"MedianW":36505
},
{
"Code":"CA",
"Value":17.4,
"MedianW":48415
},
{
"Code":"CO",
"Value":9.2,
"MedianW":49549
},
{
"Code":"CT",
"Value":14.3,
"MedianW":58337
},
{
"Code":"DE",
"Value":11,
"MedianW":48284
},
{
"Code":"DC",
"Value":10.9,
"MedianW":50186
},
{
"Code":"FL",
"Value":6.9,
"MedianW":41915
},
{
"Code":"GA",
"Value":6.3,
"MedianW":41214
},
{
"Code":"HI",
"Value":23.6,
"MedianW":49919
},
{
"Code":"ID",
"Value":5.8,
"MedianW":41785
},
{
"Code":"IL",
"Value":16.3,
"MedianW":47485
},
{
"Code":"IN",
"Value":10.2,
"MedianW":42089
},
{
"Code":"IA",
"Value":12,
"MedianW":42207
},
{
"Code":"KS",
"Value":8.4,
"MedianW":42577
},
{
"Code":"KY",
"Value":13,
"MedianW":40020
},
{
"Code":"LA",
"Value":5.5,
"MedianW":37967
},
{
"Code":"ME",
"Value":13.1,
"MedianW":41488
},
{
"Code":"MD",
"Value":13.1,
"MedianW":58269
},
{
"Code":"MA",
"Value":14.6,
"MedianW":55602
},
{
"Code":"MI",
"Value":16.8,
"MedianW":45029
},
{
"Code":"MN",
"Value":15,
"MedianW":48097
},
{
"Code":"MS",
"Value":4.2,
"MedianW":36240
},
{
"Code":"MO",
"Value":10.4,
"MedianW":41092
},
{
"Code":"MT",
"Value":14.8,
"MedianW":42301
},
{
"Code":"NE",
"Value":9,
"MedianW":41861
},
{
"Code":"NV",
"Value":16.1,
"MedianW":44924
},
{
"Code":"NH",
"Value":10.7,
"MedianW":52588
},
{
"Code":"NJ",
"Value":16.6,
"MedianW":61146
},
{
"Code":"NM",
"Value":7.4,
"MedianW":38349
},
{
"Code":"NY",
"Value":25.8,
"MedianW":47790
},
{
"Code":"NC",
"Value":4.7,
"MedianW":40710
},
{
"Code":"ND",
"Value":8.5,
"MedianW":41557
},
{
"Code":"OH",
"Value":14.1,
"MedianW":42814
},
{
"Code":"OK",
"Value":9.5,
"MedianW":40665
},
{
"Code":"OR",
"Value":14.9,
"MedianW":43160
},
{
"Code":"PA",
"Value":13.7,
"MedianW":47439
},
{
"Code":"RI",
"Value":17.8,
"MedianW":46896
},
{
"Code":"SC",
"Value":4.6,
"MedianW":39238
},
{
"Code":"SD",
"Value":5.8,
"MedianW":38071
},
{
"Code":"TN",
"Value":7.4,
"MedianW":39891
},
{
"Code":"TX",
"Value":6,
"MedianW":41225
},
{
"Code":"UT",
"Value":5.4,
"MedianW":50976
},
{
"Code":"VT",
"Value":13.2,
"MedianW":46019
},
{
"Code":"VA",
"Value":6.4,
"MedianW":53328
},
{
"Code":"WA",
"Value":19.7,
"MedianW":52724
},
{
"Code":"WV",
"Value":13.6,
"MedianW":41499
},
{
"Code":"WI",
"Value":13.1,
"MedianW":43661
},
{
"Code":"WY",
"Value":6.4,
"MedianW":45336
}
]
The problem is that you use Code and Value parameters instead of lowercase. So if you replace it, and add informaiton about median to pointFormat, when all will work.
Data:
{
"code": "AL",
"value": 11.8,
"MedianW": 40120
}
Tooltip: pointFormat: '{point.code}: {point.value}/km² : MedianW: {point.MedianW}'
Example: http://jsfiddle.net/9NMbm/
Related
Make highcharts fullscreen also fullscreen the div wrapping the chart
Is there a way to make the div wrapping the chart part of the fullscreen as well? This is my code: fiddle THis code only fulscreens the chart. When I try and do to point the div I need in the fullscreen: Highcharts.FullScreen = function(container) { this.init(ontainer.parentNode.parentNode); }; My fullscreen is getting cut off and also not adding the parent div to the full screen. Is there to make the whole div with id yo and the other div inside (<div>Random Data and text.......</div>) as part of the fullscreen?
You can connect the content of a custom element through chart.renderer.text().add() by specifying this element with the html() method: chart.renderer.text(selector.html(), 0, 0).add(); ...hiding this element through css, set the display: none: .random_data { display: none; } This is the piece of code to add: function (chart) { chart.renderer .text($(".random_data").html(), 10, 10) .css({ color: "green", fontSize: "12px", }) .add(); } JavaScript: let chart = Highcharts.chart( "container", { chart: { type: "column", }, title: { text: "", }, xAxis: { categories: ["one", "two", "three"], }, plotOptions: { column: { pointPadding: 0.2, borderWidth: 0, }, }, yAxis: { title: { text: "", }, endOnTick: false, }, series: [ { name: "books", data: [ ["one", 64161.71548379661], ["two", 3570.6197029028076], ["three", -200.70625619033547], ], marker: { symbol: "circle", }, }, ], }, function (chart) { chart.renderer .text($(".random_data").html(), 10, 10) .css({ color: "green", fontSize: "12px", }) .add(); } ); let btn = document.getElementById("btn"); btn.addEventListener("click", function () { Highcharts.FullScreen = function (container) { console.log(container.parentNode.parentNode); this.init(container.parentNode); // main div of the chart }; Highcharts.FullScreen.prototype = { init: function (container) { if (container.requestFullscreen) { container.requestFullscreen(); } else if (container.mozRequestFullScreen) { container.mozRequestFullScreen(); } else if (container.webkitRequestFullscreen) { container.webkitRequestFullscreen(); } else if (container.msRequestFullscreen) { container.msRequestFullscreen(); } }, }; chart.fullscreen = new Highcharts.FullScreen(chart.container); }); CSS: .random_data { display: none; } HTML: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://code.highcharts.com/highcharts.js"></script> <div id="yo"> <div class="random_data">Random Data and text.......</div> <div id="container" style="height: 400px; margin-top: 1em;"></div> </div> <button id="btn"> Show full screen </button>
Highcharts - Change value of text box when drilling down through chart
Tricky one to explain this so please bear with me. I have this Large Tree Map created with Highcharts: http://jsfiddle.net/mb3hu1px/2/ var data = { "ARS": { "01To03Years": { "N": { "ARGENTINA": 951433 } }, "Above05Years": { "N": { "ARGENTINA": 3719665 } } }, "CNY": { "03To05Years": { "N": { "CHINA": 162950484 } } }, "COP": { "Above05Years": { "N": { "COLOMBIA": 323390000 } } }, "EUR": { "01To03Years": { "Y": { "BELGIUM": 393292575 } } } }, points = [], currencyPoints, currencyVal, currencyI = 0, periodPoints, periodI, yesOrNoPoints, yesOrNoI, currency, period, yesOrNo, mil, causeMil, causeMilI, causeName = { 'N': 'Country Name', 'Y': 'Country Name' }; for (currency in data) { if (data.hasOwnProperty(currency)) { currencyVal = 0; currencyPoints = { id: 'id_' + currencyI, name: currency, color: Highcharts.getOptions().colors[currencyI] }; periodI = 0; for (period in data[currency]) { if (data[currency].hasOwnProperty(period)) { periodPoints = { id: currencyPoints.id + '_' + periodI, name: period, parent: currencyPoints.id }; points.push(periodPoints); yesOrNoI = 0; for (yesOrNo in data[currency][period]) { if (data[currency][period].hasOwnProperty(yesOrNo)) { yesOrNoPoints = { id: periodPoints.id + '_' + yesOrNoI, name: yesOrNo, parent: periodPoints.id, }; causeMilI = 0; for (mil in data[currency][period][yesOrNo]) { if (data[currency][period][yesOrNo].hasOwnProperty(mil)) { causeMil = { id: yesOrNoPoints.id + '_' + causeMilI, name: mil, parent: yesOrNoPoints.id, value: Math.round(+data[currency][period][yesOrNo][mil]) }; currencyVal += causeMil.value; points.push(causeMil); causeMilI = causeMilI + 1; } } points.push(yesOrNoPoints); yesOrNoI = yesOrNoI + 1; } } periodI = periodI + 1; } } currencyPoints.value = Math.round(currencyVal / periodI); points.push(currencyPoints); currencyI = currencyI + 1; } } Highcharts.chart('container', { series: [{ type: 'treemap', layoutAlgorithm: 'squarified', allowDrillToNode: true, animationLimit: 1000, dataLabels: { enabled: false }, levelIsConstant: false, levels: [{ level: 1, dataLabels: { enabled: true }, borderWidth: 3 }], data: points }], title: { text: '' } }); #container { min-width: 300px; max-width: 600px; margin: 0 auto; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/modules/heatmap.js"></script> <script src="https://code.highcharts.com/modules/treemap.js"></script> <div id="container"></div> <textarea name="text" id="text" cols="30" rows="10"></textarea> And as you can see there is also a text area underneath. What I want is for every level that is clicked through on the chart, the text area updates with some random text. So for example on the first drill down, the text area could literally just print out level 1, the second drill down print level 2 etc. etc. If anyone needs anything else from my end please let me know. Many thanks:)
You can do this several ways. Here is how to do it with plotOptions.series.point.events.click. What you need to do is capture the point click and render some text. As you do not describe what text to show this will just update the textarea with the clicked point's properties name and value. Highcharts.chart('container', { series: [{ point: { events: { click: function() { var thePointName = this.name, thePointValue = this.value; $('#text').val(function(_, val) { return 'Category: ' + thePointName + ', value: ' + thePointValue; }); } } }, type: 'treemap', layoutAlgorithm: 'squarified', allowDrillToNode: true, animationLimit: 1000, dataLabels: { enabled: false }, levelIsConstant: false, levels: [{ level: 1, dataLabels: { enabled: true }, borderWidth: 3 }], data: points }], title: { text: '' } }); Live example.
i cant link local json file to the webpage
i am doing a school proget where i have to link a json data local file to a http webpage to get the data but i can't get the results. the code below is the json local code which i want to put in the webpage instead of this code $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=activity.json&callback=?', function (activity) ?({ "xData": [0.001567,0.011765,0.022194,0.032316,0.04266,0.063668,0.074477,0.085323,0.09576,0.106078,0.116096,0.137524,0.148342,0.159059,0.170005,0.180716,0.191407,0.212538,0.222819,0.233929,0.244239,0.255301,0.266081,0.287527,0.298115,0.309392,0.320217,0.330928,0.341401,0.361717,0.372173,0.382337,0.39294,0.403072,0.413454,0.434618,0.444845,0.455745,0.465785,0.475987,0.486064,0.507086,0.517517,0.527961,0.538242,0.548414,0.558444,0.578941,0.589212,0.599472,0.60977,0.620178,0.630189,0.650782,0.661001,0.671137,0.681175,0.691235,0.702012,0.722644,0.733166,0.743824,0.754059,0.764109,0.774519,0.795597,0.805721,0.81592,0.826139,0.836369,0.846826,0.86771,0.87803,0.888342,0.898695,0.908723,0.91922,0.939802,0.950378,0.960776,0.971377,0.981843,0.992312,1.013125,1.023302,1.033488,1.043822,1.054203,1.065019,1.086078,1.09635,1.106421,1.117028,1.127541,1.138599,1.159588,1.170167,1.180741,1.190794,1.201112,1.211355,1.233278,1.243477,1.254957,1.265227,1.276378,1.285656,1.297311,1.308367,1.318715,1.329589,1.340834,1.352388,1.375063,1.385369,1.396291,1.408156,1.418989,1.429535,1.451141,1.462205,1.473011,1.483844,1.494311,1.514761,1.525336,1.535858,1.546476,1.557325,1.567512,1.590091,1.600925,1.612303,1.622558,1.633071,1.643555,1.66484,1.675722,1.685986,1.696733,1.706895,1.719102,1.741295,1.752144,1.762688,1.773713,1.784052,1.795705,1.817305,1.827465,1.838408,1.849369,1.860023,1.871438,1.89257,1.90323,1.914398,1.924634,1.934642,1.945212,1.966275,1.976294,1.986422,1.996652,2.008005,2.018309,2.041139,2.051221,2.0613,2.072507,2.08342,2.094075,2.114574,2.125286,2.135765,2.146845,2.157966,2.169391,2.190921,2.200899,2.212709,2.222671,2.232908,2.244001,2.264898,2.275703,2.286885,2.298115,2.310186,2.32059,2.344695,2.354843,2.366387,2.379001,2.390328,2.402215,2.423134,2.433156,2.444912,2.457061,2.468253,2.478978,2.499832,2.513223,2.52561,2.538429,2.548659,2.560809,2.581308,2.592816,2.603963,2.615992,2.626242,2.638223,2.660346,2.671583,2.681938,2.69265,2.70588,2.716296,2.740081,2.75085,2.761319,2.772027,2.782659,2.793531,2.816194,2.828031,2.839243,2.851443,2.863884,2.874359,2.895246,2.906506,2.91761,2.92786,2.938937,2.950218,2.973357,2.98366,2.994639,3.005213,3.01666,3.02761,3.050025,3.061713,3.071828,3.082787,3.093422,3.105289,3.127231,3.138982,3.149755,3.160217,3.171299,3.191571,3.202226,3.213225,3.223987,3.234092,3.244644,3.265939,3.276411,3.286489,3.297156,3.307909,3.319018,3.34064,3.351107,3.361683,3.373136,3.384768,3.395457,3.417722,3.429096,3.439122,3.449679,3.459868,3.469997,3.492679,3.503647,3.514941,3.525858,3.538746,3.550422,3.572255,3.58452,3.595367,3.605736,3.617401,3.628324,3.652523,3.663679,3.67378,3.684605,3.695595,3.705843,3.728706,3.739169,3.750205,3.761258,3.771771,3.781911,3.804724,3.81631,3.826313,3.837847,3.85049,3.860999,3.88262,3.892937,3.903053,3.913656,3.924698,3.935126,3.956362,3.966543,3.976899,3.98752,3.997644,4.008721,4.029852,4.040633,4.051006,4.06126,4.071761,4.083526,4.10749,4.117855,4.128661,4.13934,4.151117,4.1624,4.184736,4.194826,4.205098,4.215261,4.225325,4.236367,4.262012,4.273794,4.285743,4.297226,4.308086,4.318245,4.340246,4.351486,4.363196,4.374465,4.387109,4.398635,4.421101,4.432135,4.444666,4.456226,4.467413,4.477804,4.498505,4.510413,4.522595,4.534044,4.545944,4.558048,4.580379,4.59312,4.605616,4.618065,4.631266,4.644086,4.667943,4.67948,4.691266,4.703019,4.715923,4.725932,4.752312,4.765224,4.777128,4.787361,4.800435,4.823353,4.836044,4.848602,4.860302,4.871112,4.882779,4.904695,4.914823,4.927074,4.938111,4.949586,4.960761,4.982911,4.9942,5.004246,5.016296,5.027215,5.038043,5.058885,5.070303,5.080649,5.093865,5.104424,5.114903,5.134965,5.146346,5.15634,5.168547,5.179066,5.191167,5.214242,5.224914,5.237573,5.249537,5.261586,5.272517,5.296154,5.306348,5.316773,5.327153,5.339961,5.350638,5.376502,5.389277,5.402142,5.412197,5.42399,5.434873,5.458466,5.470907,5.482679,5.493339,5.50574,5.516349,5.538897,5.549552,5.56083,5.571879,5.583764,5.59509,5.619028,5.629925,5.640716,5.650957,5.661787,5.671957,5.693974,5.704919,5.717491,5.731152,5.744728,5.755687,5.778668,5.791951,5.80409,5.815697,5.828482,5.840501,5.864145,5.875704,5.887893,5.900147,5.912517,5.924894,5.948897,5.959155,5.970262,5.981632,5.992996,6.00356,6.027256,6.038776,6.050959,6.061351,6.071864,6.082436,6.104054,6.115602,6.127623,6.139058,6.150639,6.161323,6.183013,6.194359,6.206269,6.218033,6.2281,6.240494,6.262584,6.275326,6.287166,6.298953,6.310644,6.321583,6.345676,6.356738,6.366782,6.377931,6.388519,6.397159], "datasets": [{ "name": "Speed", "data": [10,20,30,40,50,60,70,80,90,100], "unit": "km/h", "type": "line", "valueDecimals": 1 }, { "name": "Elevation", "data": [10,20,30,40,50,60,70,80,90,100], "unit": "m", "type": "area", "valueDecimals": 0 }, { "name": "Consumo Carburante", "data": [10,20,30,40,50,60,70,80,90,100], "unit": "l", "type": "area", "valueDecimals": 0 }] }); <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Highcharts Example</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <style type="text/css"> .chart { min-width: 320px; max-width: 800px; height: 220px; margin: 0 auto; } </style> <!-- http://doc.jsfiddle.net/use/hacks.html#css-panel-hack --> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style> </style> <script type="text/javascript"> /* The purpose of this demo is to demonstrate how multiple charts on the same page can be linked through DOM and Highcharts events and API methods. It takes a standard Highcharts config with a small variation for each data set, and a mouse/touch event handler to bind the charts together. */ $(function () { /** * In order to synchronize tooltips and crosshairs, override the * built-in events with handlers defined on the parent element. */ $('#container').bind('mousemove touchmove', function (e) { var chart, point, i; for (i = 0; i < Highcharts.charts.length; i = i + 1) { chart = Highcharts.charts[i]; e = chart.pointer.normalize(e); // Find coordinates within the chart point = chart.series[0].searchPoint(e, true); // Get the hovered point if (point) { point.onMouseOver(); // Show the hover marker chart.tooltip.refresh(point); // Show the tooltip chart.xAxis[0].drawCrosshair(e, point); // Show the crosshair } } }); /** * Override the reset function, we don't need to hide the tooltips and crosshairs. */ Highcharts.Pointer.prototype.reset = function () { return undefined; }; /** * Synchronize zooming through the setExtremes event handler. */ function syncExtremes(e) { var thisChart = this.chart; if (e.trigger !== 'syncExtremes') { // Prevent feedback loop Highcharts.each(Highcharts.charts, function (chart) { if (chart !== thisChart) { if (chart.xAxis[0].setExtremes) { // It is null while updating chart.xAxis[0].setExtremes(e.min, e.max, undefined, false, { trigger: 'syncExtremes' }); } } }); } } // Get the data. The contents of the data file can be viewed at // https://github.com/highcharts/highcharts/blob/master/samples/data/activity.json // here i want to add my own json file which is local but i cant add it.. //********************** Problem ************************************** $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=activity.json&callback=?', function (activity) { $.each(activity.datasets, function (i, dataset) { // Add X values dataset.data = Highcharts.map(dataset.data, function (val, j) { return [activity.xData[j], val]; }); $('<div class="chart">') .appendTo('#container') .highcharts({ chart: { marginLeft: 40, // Keep all charts left aligned spacingTop: 20, spacingBottom: 20, zoomType: 'x' }, title: { text: dataset.name, align: 'left', margin: 0, x: 30 }, credits: { enabled: false }, legend: { enabled: false }, xAxis: { crosshair: true, events: { setExtremes: syncExtremes }, labels: { format: '{value} km' } }, yAxis: { title: { text: null } }, tooltip: { positioner: function () { return { x: this.chart.chartWidth - this.label.width, // right aligned y: -1 // align to title }; }, borderWidth: 0, backgroundColor: 'none', pointFormat: '{point.y}', headerFormat: '', shadow: false, style: { fontSize: '18px' }, valueDecimals: dataset.valueDecimals }, series: [{ data: dataset.data, name: dataset.name, type: dataset.type, color: Highcharts.getOptions().colors[i], fillOpacity: 0.3, tooltip: { valueSuffix: ' ' + dataset.unit } }] }); }); }); }); </script> <body> <script src="https://code.highcharts.com/highcharts.js"></script> <div id="container"></div> <!-- ******************************************************************************************** --> </body> </html>
save the below structure into local json file: { "xData": [0.001567,0.011765,0.022194,0.032316,0.04266,0.063668,0.074477,0.085323,0.09576,0.106078,0.116096,0.137524,0.148342,0.159059,0.170005,0.180716,0.191407,0.212538,0.222819,0.233929,0.244239,0.255301,0.266081,0.287527,0.298115,0.309392,0.320217,0.330928,0.341401,0.361717,0.372173,0.382337,0.39294,0.403072,0.413454,0.434618,0.444845,0.455745,0.465785,0.475987,0.486064,0.507086,0.517517,0.527961,0.538242,0.548414,0.558444,0.578941,0.589212,0.599472,0.60977,0.620178,0.630189,0.650782,0.661001,0.671137,0.681175,0.691235,0.702012,0.722644,0.733166,0.743824,0.754059,0.764109,0.774519,0.795597,0.805721,0.81592,0.826139,0.836369,0.846826,0.86771,0.87803,0.888342,0.898695,0.908723,0.91922,0.939802,0.950378,0.960776,0.971377,0.981843,0.992312,1.013125,1.023302,1.033488,1.043822,1.054203,1.065019,1.086078,1.09635,1.106421,1.117028,1.127541,1.138599,1.159588,1.170167,1.180741,1.190794,1.201112,1.211355,1.233278,1.243477,1.254957,1.265227,1.276378,1.285656,1.297311,1.308367,1.318715,1.329589,1.340834,1.352388,1.375063,1.385369,1.396291,1.408156,1.418989,1.429535,1.451141,1.462205,1.473011,1.483844,1.494311,1.514761,1.525336,1.535858,1.546476,1.557325,1.567512,1.590091,1.600925,1.612303,1.622558,1.633071,1.643555,1.66484,1.675722,1.685986,1.696733,1.706895,1.719102,1.741295,1.752144,1.762688,1.773713,1.784052,1.795705,1.817305,1.827465,1.838408,1.849369,1.860023,1.871438,1.89257,1.90323,1.914398,1.924634,1.934642,1.945212,1.966275,1.976294,1.986422,1.996652,2.008005,2.018309,2.041139,2.051221,2.0613,2.072507,2.08342,2.094075,2.114574,2.125286,2.135765,2.146845,2.157966,2.169391,2.190921,2.200899,2.212709,2.222671,2.232908,2.244001,2.264898,2.275703,2.286885,2.298115,2.310186,2.32059,2.344695,2.354843,2.366387,2.379001,2.390328,2.402215,2.423134,2.433156,2.444912,2.457061,2.468253,2.478978,2.499832,2.513223,2.52561,2.538429,2.548659,2.560809,2.581308,2.592816,2.603963,2.615992,2.626242,2.638223,2.660346,2.671583,2.681938,2.69265,2.70588,2.716296,2.740081,2.75085,2.761319,2.772027,2.782659,2.793531,2.816194,2.828031,2.839243,2.851443,2.863884,2.874359,2.895246,2.906506,2.91761,2.92786,2.938937,2.950218,2.973357,2.98366,2.994639,3.005213,3.01666,3.02761,3.050025,3.061713,3.071828,3.082787,3.093422,3.105289,3.127231,3.138982,3.149755,3.160217,3.171299,3.191571,3.202226,3.213225,3.223987,3.234092,3.244644,3.265939,3.276411,3.286489,3.297156,3.307909,3.319018,3.34064,3.351107,3.361683,3.373136,3.384768,3.395457,3.417722,3.429096,3.439122,3.449679,3.459868,3.469997,3.492679,3.503647,3.514941,3.525858,3.538746,3.550422,3.572255,3.58452,3.595367,3.605736,3.617401,3.628324,3.652523,3.663679,3.67378,3.684605,3.695595,3.705843,3.728706,3.739169,3.750205,3.761258,3.771771,3.781911,3.804724,3.81631,3.826313,3.837847,3.85049,3.860999,3.88262,3.892937,3.903053,3.913656,3.924698,3.935126,3.956362,3.966543,3.976899,3.98752,3.997644,4.008721,4.029852,4.040633,4.051006,4.06126,4.071761,4.083526,4.10749,4.117855,4.128661,4.13934,4.151117,4.1624,4.184736,4.194826,4.205098,4.215261,4.225325,4.236367,4.262012,4.273794,4.285743,4.297226,4.308086,4.318245,4.340246,4.351486,4.363196,4.374465,4.387109,4.398635,4.421101,4.432135,4.444666,4.456226,4.467413,4.477804,4.498505,4.510413,4.522595,4.534044,4.545944,4.558048,4.580379,4.59312,4.605616,4.618065,4.631266,4.644086,4.667943,4.67948,4.691266,4.703019,4.715923,4.725932,4.752312,4.765224,4.777128,4.787361,4.800435,4.823353,4.836044,4.848602,4.860302,4.871112,4.882779,4.904695,4.914823,4.927074,4.938111,4.949586,4.960761,4.982911,4.9942,5.004246,5.016296,5.027215,5.038043,5.058885,5.070303,5.080649,5.093865,5.104424,5.114903,5.134965,5.146346,5.15634,5.168547,5.179066,5.191167,5.214242,5.224914,5.237573,5.249537,5.261586,5.272517,5.296154,5.306348,5.316773,5.327153,5.339961,5.350638,5.376502,5.389277,5.402142,5.412197,5.42399,5.434873,5.458466,5.470907,5.482679,5.493339,5.50574,5.516349,5.538897,5.549552,5.56083,5.571879,5.583764,5.59509,5.619028,5.629925,5.640716,5.650957,5.661787,5.671957,5.693974,5.704919,5.717491,5.731152,5.744728,5.755687,5.778668,5.791951,5.80409,5.815697,5.828482,5.840501,5.864145,5.875704,5.887893,5.900147,5.912517,5.924894,5.948897,5.959155,5.970262,5.981632,5.992996,6.00356,6.027256,6.038776,6.050959,6.061351,6.071864,6.082436,6.104054,6.115602,6.127623,6.139058,6.150639,6.161323,6.183013,6.194359,6.206269,6.218033,6.2281,6.240494,6.262584,6.275326,6.287166,6.298953,6.310644,6.321583,6.345676,6.356738,6.366782,6.377931,6.388519,6.397159], "datasets": [{ "name": "Speed", "data": [10,20,30,40,50,60,70,80,90,100], "unit": "km/h", "type": "line", "valueDecimals": 1 }, { "name": "Elevation", "data": [10,20,30,40,50,60,70,80,90,100], "unit": "m", "type": "area", "valueDecimals": 0 }, { "name": "Consumo Carburante", "data": [10,20,30,40,50,60,70,80,90,100], "unit": "l", "type": "area", "valueDecimals": 0 }] } Anyway, the most preferable way is to use getJson method: $.getJSON( "test.json", function( data ) { var items = []; $.each( data, function( key, val ) { ... process data }); ... });
Highchart with Range selector for SQL Data in html website
i want to add a range selector in my Chart, but i don´t know how to do it. i´ve tried some example from jsfiddle , but it´s not working. Here is my code: <meta http-equiv="refresh" content="65;url=http://localhost/23-1_chart.php"/> <title>XXX</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="css/XXX.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script> <script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> <script type="text/javascript" src="data.js" ></script> </head> <body> <div id="chart" style="height: 400px; margin: 0 auto"></div> <script> $(function() { //Highcharts with mySQL and PHP - Ajax101.com var Voc_value = []; var time = []; var switch1 = true; $.get('23-1_values.php', function(data) { data = data.split('/'); for (var i in data) { if (switch1 == true) { time.push(data[i]); switch1 = false; } else { Voc_value.push(parseFloat(data[i])); switch1 = true; } } time.pop(); // cursor $('#chart').highcharts({ chart : { type : 'spline' }, title : { text : 'VOC-Value-A.ROOM' }, subtitle : { text : 'Room A' }, xAxis : { title : { text : 'time' }, categories : time }, yAxis : { title : { text : 'VOC-value in ppm' }, labels : { formatter : function() { return this.value + 'VOCvalue' } } }, tooltip : { crosshairs : true, shared : true, valueSuffix : 'ppm' }, plotOptions : { spline : { marker : { radius : 4, lineColor : '#666666', lineWidth : 1 } } }, series : [{ name : 'VOC-value in ppm', data : Voc_value }] }); }); });</script> First i read the sql values and put it in 23-1_values.php. My sql values are reading from this php-page 23.1_values.php and then the chart is build. I have the datetime (day-hour-min-s) in the abscissae axis and the ppm value in the ordinate axis I´m getting too much values and want to reduce the dateformat and add a range selector in the chart. How can i do it? Thanks
i don´t really know what i have done, but it is working now. Thank you very much for helping me.Here is the code: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>XXXXXXXXX</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="http://code.highcharts.com/stock/highstock.js"></script> <script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/stock/modules/exporting.js"></script> <script type="text/javascript"> $(document).ready(function() { $.getJSON("XXX.php", function(data) { // Create a timer var start = + new Date(); // Create the chart $('#container').highcharts('StockChart', { chart: { events: { load: function(chart) { this.setTitle(null, { text: 'Built chart at '+ (new Date() - start) +'ms' }); } }, zoomType: 'x' }, rangeSelector: { buttons: [{ type: 'day', count: 1, text: '24h' }, { type: 'week', count: 1, text: '1w' }, { type: 'month', count: 1, text: '1m' }, { type: 'month', count: 6, text: '6m' }, { type: 'year', count: 1, text: '1y' }, { type: 'all', text: 'All' }], selected: 0 }, yAxis: { title: { text: 'XX' } }, title: { text: 'XX' }, subtitle: { text: 'Built chart at...' // dummy text to reserve space for dynamic subtitle }, series: [{ name: 'XX', type: 'area', data: data, tooltip: { valueDecimals: 1, valueSuffix: ' ppm' }, fillColor : { linearGradient : { x1: 0, y1: 0, x2: 0, y2: 1 }, stops : [[0, Highcharts.getOptions().colors[0]], [1, 'rgba(0,0,0,0)']] }, }/*, { name: 'Temperatur', type: 'area', data: datarasp, tooltip: { valueDecimals: 1, valueSuffix: ' °C' }, fillColor : { linearGradient : { x1: 0, y1: 0, x2: 0, y2: 1 }, stops : [[0, Highcharts.getOptions().colors[0]], [1, 'rgba(0,0,0,0)']] }, }*/] }); }); }); </script> </head> <body> <div id="container" style="height: 500px; min-width: 500px"></div> </body> </html> Hope it will help someone
FlotChart do not work zooming mode
I have following example: http://jsfiddle.net/ondra15/7mb8K/1/. I want to have together two example (multiple axes and zooming). Example zooming do not work correct - if I indicate some data in chart for zooming - do not work. Nothing happens. Original Zooming (correct) solution works here http://www.flotcharts.org/flot/examples/zooming/index.html Can any some idea for my code? Thanks code
Hi I managed to get it working using code from an example I found here. I will update your jsfiddle too: <script type="text/javascript"> var datasets = { ... }; data = null; function plotByChoice(doAll) { data = []; if (doAll != null) { $.each(datasets, function (key, val) { data.push(val); }); } else { $('#legend .legendCB').each( function () { if (this.checked) { data.push(datasets[this.id]); } else { data.push({ label: this.id, data: [] }) } } ); } $.plot($("#placeholder"), data, { yaxes: [{ min: 0 }, { position: "right" }], xaxis: { tickDecimals: 0 }, legend: { container: legend, labelFormatter: function (label, series) { var cb = '<input class="legendCB" type="checkbox" '; if (series.data.length > 0) { cb += 'checked="true" '; } cb += 'id="' + label + '" /> '; cb += label; return cb; } }, selection: { mode: "x" } }); $('#legend').find("input").click(function () { setTimeout(plotByChoice, 100); }); } plotByChoice(true); // Create the overview plot var overview = $.plot("#overview", data, { legend: { show: false }, series: { lines: { show: true, lineWidth: 1 }, shadowSize: 0 }, xaxis: { ticks: 4 }, yaxes: [{ min: 0 }, { position: "right" }], grid: { color: "#999" }, selection: { mode: "x" } }); $("#placeholder").bind("plotselected", function (event, ranges) { var options = { series: { lines: { show: true }, points: { show: true } }, legend: { noColumns: 2 }, xaxis: { tickDecimals: 0 }, yaxis: { min: 0 }, selection: { mode: "x" } }; var placeholder = $("#placeholder"); placeholder.bind("plotselected", function (event, ranges) { $("#selection").text(ranges.xaxis.from.toFixed(1) + " to " + ranges.xaxis.to.toFixed(1)); plot = $.plot(placeholder, data, $.extend(true, {}, options, { xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to } })); }); // don't fire event on the overview to prevent eternal loop overview.setSelection(ranges, true); }); $("#overview").bind("plotselected", function (event, ranges) { plot.setSelection(ranges); }); </script>