glBindVertexArray does not switch VAO in display() but does in init() - draw

I am trying to learn how to program OpenGL. Right now I am writing a program that draws to cubes. I have each cube stored in a separate VBO. This is the code for this.
void
init()
{
enum { Vertices, Colors, Elements, NumVBOs };
GLuint buffers[NumVBOs];
glGenVertexArrays(NumVAOs,VAO);
{
GLfloat vertices[][3] = {
{ -0.5, -0.5, -0.5 },
{ 0.5, -0.5, -0.5 },
{ 0.5, 0.5, -0.5 },
{ -0.5, 0.5, -0.5 },
{ -0.5, -0.5, 0.5 },
{ 0.5, -0.5, 0.5 },
{ 0.5, 0.5, 0.5 },
{ -0.5, 0.5, 0.5 }
};
GLfloat cubeColors[][3] = {
{ 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 1.0, 1.0 },
{ 1.0, 0.0, 0.0 },
{ 1.0, 0.0, 1.0 },
{ 1.0, 1.0, 0.0 },
{ 1.0, 1.0, 1.0 },
};
GLubyte indices[][4] = {
{ 0, 1, 2, 3 },
{ 4, 7, 6, 5 },
{ 0, 4, 5, 1 },
{ 3, 2, 6, 7 },
{ 0, 3, 7, 4 },
{ 1, 5, 6, 2 }
};
glBindVertexArray(VAO[Cube1]);
glGenBuffers(NumVBOs, buffers);
glBindBuffer(GL_ARRAY_BUFFER, buffers[Vertices]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices,
GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, buffers[Colors]);
glBufferData(GL_ARRAY_BUFFER,sizeof(cubeColors),cubeColors,GL_STATIC_DRAW);
glColorPointer(3,GL_FLOAT,0,BUFFER_OFFSET(0));
glEnableClientState(GL_COLOR_ARRAY);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[Elements]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices,
GL_STATIC_DRAW);
}
{
GLfloat vertices2[][3] = {
{ -0.5, -0.5, -1.5 },
{ 0.5, -0.5, -1.5 },
{ 0.5, 0.5, -1.5 },
{ -0.5, 0.5, -1.5 },
{ -0.5, -0.5, -2.5 },
{ 0.5, -0.5, -2.5 },
{ 0.5, 0.5, -2.5 },
{ -0.5, 0.5, -2.5 }
};
GLfloat cubeColors2[][3] = {
{ 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 1.0, 1.0 },
{ 1.0, 0.0, 0.0 },
{ 1.0, 0.0, 1.0 },
{ 1.0, 1.0, 0.0 },
{ 1.0, 1.0, 1.0 },
};
GLubyte indices2[][4] = {
{ 0, 1, 2, 3 },
{ 4, 7, 6, 5 },
{ 0, 4, 5, 1 },
{ 3, 2, 6, 7 },
{ 0, 3, 7, 4 },
{ 1, 5, 6, 2 }
};
glBindVertexArray(VAO[Cube2]);
glGenBuffers(NumVBOs, buffers);
glBindBuffer(GL_ARRAY_BUFFER, buffers[Vertices]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices2), vertices2,
GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, buffers[Colors]);
glBufferData(GL_ARRAY_BUFFER,sizeof(cubeColors2),cubeColors2,GL_STATIC_DRAW);
glColorPointer(3,GL_FLOAT,0,BUFFER_OFFSET(0));
glEnableClientState(GL_COLOR_ARRAY);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[Elements]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices2), indices2,
GL_STATIC_DRAW);
}
glEnable(GL_DEPTH_TEST);
}
When this is called in display()
glBindVertexArray[VAO[Cube1]];
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
glBindVertexArray[VAO[Cube2]];
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
The program only draws Cube2. However, if I insert
glBindVertexArray[VAO[Cube1]];
at the end of init(), it will draw Cube1 only instead.
Right now I am confused. I would like to be able to use VAOs for more complicated applications but am stuck at this point.

glBindVertexArray[VAO[Cube1]];
Should have been
glBindVertexArray(VAO[Cube1]);

Related

React + json output in chart

I have a simple json file:
{
"id": 1,
"name": "Bitcoin",
"quantity": 1,
"price": 1,
"old_price": 0.99,
"info": "The most famous one",
"archived_data": [
{
"id": 0,
"name": "jan",
"sold": 5,
"bought": 3
},
{
"id": 1,
"name": "feb",
"sold": 15,
"bought": 30
},
{
"id": 2,
"name": "mar",
"sold": 5,
"bought": 3
},
{
"id": 3,
"name": "apr",
"sold": 15,
"bought": 30
}
]
}
I now want to display them in my chart:
import CanvasJSReact from '../plugins/canvasjs.react';
import React, {Component} from 'react';
const CanvasJSChart = CanvasJSReact.CanvasJSChart;
class CryptoChart extends Component {
constructor(props) {
super(props);
this.toggleDataSeries = this.toggleDataSeries.bind(this);
}
toggleDataSeries(e){
e.dataSeries.visible = !(typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible);
this.chart.render();
}
render() {
const options = {
theme: "light2",
animationEnabled: true,
axisX: {
title: "Months"
},
axisY: {
title: "Sold",
titleFontColor: "#007bff",
lineColor: "#007bff",
labelFontColor: "#007bff",
tickColor: "#007bff"
},
axisY2: {
title: "Bought",
titleFontColor: "#51CDA0",
lineColor: "#51CDA0",
labelFontColor: "#51CDA0",
tickColor: "#51CDA0"
},
toolTip: {
shared: true
},
legend: {
cursor: "pointer",
itemclick: this.toggleDataSeries
},
data: [
{
type: "spline",
name: "Sold",
showInLegend: true,
xValueFormatString: "MMM YYYY",
yValueFormatString: "#,##0 Units",
dataPoints: [
{ x: new Date(2020, 0, 1), y: this.props.crypto.archived_data[0].sold },
{ x: new Date(2020, 1, 1), y: this.props.crypto.archived_data[1].sold },
{ x: new Date(2020, 2, 1), y: this.props.crypto.archived_data[2].sold },
{ x: new Date(2020, 3, 1), y: this.props.crypto.archived_data[3].sold },
{ x: new Date(2020, 4, 1), y: this.props.crypto.archived_data[4].sold },
{ x: new Date(2020, 5, 1), y: this.props.crypto.archived_data[5].sold },
{ x: new Date(2020, 6, 1), y: this.props.crypto.archived_data[6].sold },
{ x: new Date(2020, 7, 1), y: this.props.crypto.archived_data[7].sold },
{ x: new Date(2020, 8, 1), y: this.props.crypto.archived_data[8].sold },
{ x: new Date(2020, 9, 1), y: this.props.crypto.archived_data[9].sold },
{ x: new Date(2020, 10, 1), y: this.props.crypto.archived_data[10].sold },
{ x: new Date(2020, 11, 1), y: this.props.crypto.quantity}
]
},
{
type: "spline",
name: "Bought",
axisYType: "secondary",
showInLegend: true,
xValueFormatString: "MMM YYYY",
yValueFormatString: "$#,##0.#",
dataPoints: [
{ x: new Date(2020, 0, 1), y: this.props.crypto.archived_data[0].bought },
{ x: new Date(2020, 1, 1), y: this.props.crypto.archived_data[1].bought },
{ x: new Date(2020, 2, 1), y: this.props.crypto.archived_data[2].bought },
{ x: new Date(2020, 3, 1), y: this.props.crypto.archived_data[3].bought },
{ x: new Date(2020, 4, 1), y: this.props.crypto.archived_data[4].bought },
{ x: new Date(2020, 5, 1), y: this.props.crypto.archived_data[5].bought },
{ x: new Date(2020, 6, 1), y: this.props.crypto.archived_data[6].bought },
{ x: new Date(2020, 7, 1), y: this.props.crypto.archived_data[7].bought },
{ x: new Date(2020, 8, 1), y: this.props.crypto.archived_data[8].bought },
{ x: new Date(2020, 9, 1), y: this.props.crypto.archived_data[9].bought },
{ x: new Date(2020, 10, 1), y: this.props.crypto.archived_data[10].bought },
{ x: new Date(2020, 11, 1), y: this.props.crypto.quantity }
]
}
]
}
return (
<div>
<CanvasJSChart options = {options} onRef={ref => this.chart = ref} />
</div>
);
}
} export default CryptoChart;
The this.props.crypto.quantity works as expected, but the this.props.crypto.archived_data[0].sold and this.props.crypto.archived_data[0].bought don't work: the app crashes and the console says
TypeError: Cannot read property '0' of undefined
Does anyone know how to output this?
Edit: Ive made a react.new here so its easier to see what is going wrong and maybe how it can be fixed

Can you animate circles on mapbox, and also, just have hollow circles

I know you can animate circles on google maps , see example
http://jsbin.com/nuwem/1/edit?html,output
.....But can you do the same thing on Mapbox
I am creating a live earthquake map www.livehazards.com. Each earthquake mag is respresent by a circle
I would just like the outline of the circle and to be able to animate it.
I have tried using circle-stroke for just the outline but it did not work
Thanks
To animate your circle you can simply change its paint property several times: map.setPaintProperty('yourmarker', 'circle-radius', 20)
If you only want the circle outline, set "circle-opacity":0 and "circle-stroke-width": 1.
Codepen
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
center: [ 2.35, 48.85 ],
zoom: 3
});
map.on('load', () => {
let radius = 1;
map.addLayer({
"id": "points",
"type": "circle",
// Create the marker
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ 2.35, 48.85 ]
}
}]
}
},
// Draw the circle
"paint": {
"circle-opacity": 0,
"circle-stroke-width": 1,
"circle-stroke-color": "#000",
"circle-radius": radius,
"circle-radius-transition": {
"duration": 0
}
}
});
// Animate the circle
setInterval(() => {
map.setPaintProperty('points', 'circle-radius', radius);
radius = ++radius % 30;
}, 50);
});
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
center: [ 2.35, 48.85 ],
zoom: 3
});
map.on('load', function() {
let radius = 1;
map.addSource("earthquakes", {
type: "geojson",
data: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_day.geojson",
});
map.addLayer({
"id": "earthquake-layer",
"type": "circle",
"source": "earthquakes",
"paint": {
"circle-opacity": 0.4,
"circle-color": "#830300",
"circle-stroke-width": 2,
"circle-stroke-color": "#fff",
"circle-radius": {
"property": "mag",
"base": 2.5,
"stops": [
[{zoom: 0, value: 2}, 1],
[{zoom: 0, value: 8}, 40],
[{zoom: 11, value: 2}, 10],
[{zoom: 11, value: 8}, 2400],
[{zoom: 20, value: 2}, 20],
[{zoom: 20, value: 8}, 6000]
"circle-radius-transition": {
"duration": 0
}
]
}
}
});
setInterval(() => {
map.setPaintProperty('eaarthquake-layer', 'circle-radius', radius);
radius = ++radius % 30
}, 50);
});

highchart activity gauge chart using json data from a file

I am new to using highcharts.js. I want to create an activity gauge chart using data from a json file or url. I have understood how they draw the chart but failed to understand the data format used in json to display the chart.
Here is my code
var options = {
chart: {
type: 'solidgauge',
marginTop: 50
},
title: {
text: 'Activity',
style: {
fontSize: '24px'
}
},
tooltip: {
borderWidth: 0,
backgroundColor: 'none',
shadow: false,
style: {
fontSize: '16px'
},
pointFormat: '{series.name}<br><span style="font-size:2em; color: {point.color}; font-weight: bold">{point.y}%</span>',
positioner: function (labelWidth, labelHeight) {
return {
x: 200 - labelWidth / 2,
y: 180
};
}
},
pane: {
startAngle: 0,
endAngle: 360,
background: [{ // Track for Move
outerRadius: '112%',
innerRadius: '88%',
backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0.3).get(),
borderWidth: 0
}, { // Track for Exercise
outerRadius: '87%',
innerRadius: '63%',
backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[1]).setOpacity(0.3).get(),
borderWidth: 0
}, { // Track for Stand
outerRadius: '62%',
innerRadius: '38%',
backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[2]).setOpacity(0.3).get(),
borderWidth: 0
}]
},
yAxis: {
min: 0,
max: 100,
lineWidth: 0,
tickPositions: []
},
plotOptions: {
solidgauge: {
borderWidth: '34px',
dataLabels: {
enabled: false
},
linecap: 'round',
stickyTracking: false
}
},
series: []
};
var gauge1;
$.getJSON('bryan.json', function(json){
console.log(json)
options.chart.renderTo = 'container';
options.series.data = json
gauge1 = new Highcharts.Chart(options);
});
/**
* In the chart load callback, add icons on top of the circular shapes
*/
function callback()
{
// Move icon
this.renderer.path(['M', -8, 0, 'L', 8, 0, 'M', 0, -8, 'L', 8, 0, 0, 8])
.attr({
'stroke': '#ffffff',
'stroke-linecap': 'round',
'stroke-linejoin': 'round',
'stroke-width': 2,
'zIndex': 10
})
.translate(190, 26)
.add(this.series[2].group);
// Exercise icon
this.renderer.path(['M', -8, 0, 'L', 8, 0, 'M', 0, -8, 'L', 8, 0, 0, 8, 'M', 8, -8, 'L', 16, 0, 8, 8])
.attr({
'stroke': '#ffffff',
'stroke-linecap': 'round',
'stroke-linejoin': 'round',
'stroke-width': 2,
'zIndex': 10
})
.translate(190, 61)
.add(this.series[2].group);
// Stand icon
this.renderer.path(['M', 0, 8, 'L', 0, -8, 'M', -8, 0, 'L', 0, -8, 8, 0])
.attr({
'stroke': '#ffffff',
'stroke-linecap': 'round',
'stroke-linejoin': 'round',
'stroke-width': 2,
'zIndex': 10
})
.translate(190, 96)
.add(this.series[2].group);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container" style="width: 400px; height: 400px; margin: 0 auto">
</div>
And here is my json data which i thout might be rendered but it didnot.
data.json
First of all, instead of options.series.data = json, you need to create the first series and then populate its data array with your data. Also, set in each point different radius and innerRadius properties. Take a look at the example below.
API Reference:
http://api.highcharts.com/highcharts/series.solidgauge.data.radius
http://api.highcharts.com/highcharts/series.solidgauge.data.innerRadius
Example:
http://jsfiddle.net/x3cne1ng/

SerializationException: error parsing file

So I'm trying to splice code together (not exactly a programming genius) to spruce up my version of the open-source game Destination Sol. Upon loading a new game, I receive the fatal error:
SerializationException: Error parsing file: res/configs/planets.json (file is essentially putting allies and enemies on planets and setting them up)
com.badlogic.gdx.utils.SerializationException: Error parsing file: res/configs/planets.json
at com.badlogic.gdx.utils.JsonReader.parse(JsonReader.java:77)
at org.destinationsol.game.planet.PlanetConfigs.<init>(PlanetConfigs.java:48)
at org.destinationsol.game.planet.PlanetManager.<init>(PlanetManager.java:53)
at org.destinationsol.game.SolGame.<init>(SolGame.java:121)
at org.destinationsol.SolApplication.startNewGame(SolApplication.java:171)
at org.destinationsol.menu.LoadingScreen.updateCustom(LoadingScreen.java:46)
at org.destinationsol.ui.SolInputManager.update(SolInputManager.java:220)
at org.destinationsol.SolApplication.update(SolApplication.java:132)
at org.destinationsol.SolApplication.safeUpdate(SolApplication.java:111)
at org.destinationsol.SolApplication.render(SolApplication.java:91)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: com.badlogic.gdx.utils.SerializationException: Error parsing JSON on line 206 near:
blaster|waveGun:0.1 a1|a2:.5 s1|s2:.5",
density: 0.1,
},
],
groundEnemies: [
{
hull: techieSmall,
items: "fixedPlasmaGun fixedPlasmaGun|fixedBlaster:.5 a2:.5 s3|s4",
money: 120,
density: 0.25,
}
at com.badlogic.gdx.utils.JsonReader.parse(JsonReader.java:548)
at com.badlogic.gdx.utils.JsonReader.parse(JsonReader.java:55)
at com.badlogic.gdx.utils.JsonReader.parse(JsonReader.java:75)
... 11 more
I was hoping someone who understands .json files better than me could tell me what I'm doing wrong. Also, here's the entire planets.json for reference:
{
rocky: {
easyOnly: true,
minGrav: 0.4,
maxGrav: 0.6,
groundTexs: "grounds/rocky",
decoTexs: "deco/rocky",
cloudTexs: "skies/cloud",
rowCount: 4,
smoothLandscape: true,
sky: {
dawnColor: "hsb 0 50 100",
dayColor: "hsb 216 40 100",
},
deco: {
grass: {
density: 0.3,
szMin: 0.1,
szMax: 0.2,
orig: "0 0.5",
allowFlip: true,
},
tree: {
density: 0.4,
szMin: 0.7,
szMax: 0.8,
orig: "0 0.5",
allowFlip: true,
},
},
highOrbitEnemies: [
{
hull: pirateOrbiter,
items: "plasmaGun|blaster s1:.24",
money: 40,
density: 0.03,
}
],
lowOrbitEnemies: [
{
hull: pirateOrbiter,
items: "bombGun s1:.24",
money: 50,
density: 0.1,
},
],
groundEnemies: [
{
hull: piratePlanetTurret,
items: "plasmaGun|blaster s1:.36",
money: 110,
density: 0.45,
},
{
hull: pirateSmall,
items: "blaster|gun s1|s2:.5",
money: 60,
density: 0.15,
},
],
station: {
hull: drome,
items: "gun|shotGun s2 rep:1:4",
},
trading: {
items: "rep plasmaClip shotGun shellClip mineClip bombGun bombClip missileClip s2 unShieldCharge",
ships: "pirateSmall pirateOrbiter pirateMedium",
mercenaries: [
{
hull: pirateSmall,
items: "blaster|gun s1 rep:1:3",
money: 100,
},
],
},
},
desert: {
minGrav: 0.6,
maxGrav: 0.8,
groundTexs: "grounds/desert",
decoTexs: "deco/desert",
cloudTexs: "skies/cloud",
rowCount: 3,
smoothLandscape: true,
sky: {
dawnColor: "hsb 130 50 100",
dayColor: "hsb 200 40 100",
},
deco: {
tree: {
density: 0.25,
szMin: 0.5,
szMax: 0.7,
orig: "0 0.5",
allowFlip: true,
},
remnant: {
density: 0.05,
szMin: 1,
szMax: 1.1,
orig: "0 0.3",
allowFlip: true,
},
cactus: {
density: 0.5,
szMin: 0.2,
szMax: 0.4,
orig: "0 0.5",
allowFlip: true,
},
},
highOrbitEnemies: [
{
hull: desertOrbiter,
items: "fixedGun a1:.25",
money: 150,
density: 0.03,
}
],
lowOrbitEnemies: [
{
hull: desertOrbiter,
items: "fixedBombGun a1:.25",
money: 100,
density: 0.1,
},
],
groundEnemies: [
{
hull: desertPlanetTurret,
items: "gun a1|a2:.5",
money: 80,
density: 0.45,
},
{
hull: desertSmall,
items: "fixedGun fixedGun:.3 a2:.75",
money: 80,
density: 0.15,
},
],
station: {
hull: drome,
items: "shotGun s3 a3 rep:1:4",
},
trading: {
items: "rep teleportCharge fixedGun bulletClip railClip cannon slugClip bombClip a3",
ships: "desertOrbiter desertSmall desertMedium",
mercenaries: [
{
hull: desertOrbiter,
items: "fixedBombGun a1:.25 rep:1:3",
money: 150,
},
],
},
},
frozen: {
hardOnly: true,
minGrav: 0.8,
maxGrav: 1.2,
rowCount: 4,
smoothLandscape: true,
groundTexs: "grounds/frozen",
decoTexs: "deco/frozen",
cloudTexs: "skies/cloud",
sky: {
dawnColor: "hsb 50 50 100",
dayColor: "hsb 125 40 100",
},
deco: {
tree: {
density: 0.4,
szMin: 0.7,
szMax: 0.8,
orig: "0 0.5",
allowFlip: true,
},
},
highOrbitEnemies: [
{
hull: techieOrbiter,
items: "fixedPlasmaGun|fixedBlaster fixedPlasmaGun|fixedBlaster|fixedEmGun:.5 a2:.75 s4",
money: 140,
density: 0.06,
}
highOrbitAllies: [
{
hull: imperialBig,
items: "fixedGun fixedShotGun a2|a3|a4 s2|s3|s4”,
density: 0.01,
},
{
hull: imperialSmall,
items: "blaster|waveGun:0.1 a1|a2:.5 s1|s2:.5", (<== The line that is causing an error)
density: 0.1,
},
],
groundEnemies: [
{
hull: techieSmall,
items: "fixedPlasmaGun fixedPlasmaGun|fixedBlaster:.5 a2:.5 s3|s4",
money: 120,
density: 0.25,
},
{
hull: techiePlanetTurret,
items: "waveGun emGun:.6 a3 s4",
money: 180,
density: 0.45,
},
],
groundAllies: [
{
hull: imperialSmall,
items: “shotGun a1:.5 s1:.5",
density: 0.5,
},
{
hull: imperialMedium,
items: "fixedGun a2|a4:.5 s2|s3:.75",
density: 0.15,
},
]
station: {
hull: drome,
items: "gun|shotGun|waveGun| a4 s4 rep:1:30”,
},
trading: {
items: "rep ",
ships: "imperialSmall imperialMedium imperialBig techieSmall techieOrbiter",
mercenaries: [
{
hull: imperialSmall,
items: "blaster|gun|waveGun a1:0.5 s1 rep:1:8",
money: 75,
},
{
hull: imperialMedium,
items: "fixedGun|fixedShotGun|fixedPlasmaGun a1|a2 s1|s2 rep:1:12",
money: 150
},
{
hull: imperialBig,
items: "fixedGun|fixedShotGun|fixedPlasmaGun fixedGun|fixedShotGun|fixedPlasmaGun:0.5 a2|a3|a4 s2|s3|s4 rep:1:48”,
money: 300,
},
{
hull: techieOrbiter,
items: "fixedGun|fixedPlasmaGun|fixedBlaster fixedGun|fixedPlasmaGun|fixedBlaster|fixedEmGun:.5 a2|a3|a4 s2|s3|s4 rep:1:48”,
money: 300,
},
],
},
},
}

Highchart speedometer take input from csv

I am trying to read the data from csv and display it as a input to Speedometer but I am unable to get the chart. Please tell me where i am going wrong.
My code is:
$(document).ready(function() {
var options = {
chart: {
type: 'gauge',
plotBackgroundColor: null,
plotBackgroundImage: null,
plotBorderWidth: 0,
plotShadow: false
},
title: {
text: 'Speedometer'
},
pane: {
startAngle: -150,
endAngle: 150,
background: [{
backgroundColor: {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
stops: [
[0, '#FFF'],
[1, '#333']
]
},
borderWidth: 0,
outerRadius: '109%'
}, {
backgroundColor: {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
stops: [
[0, '#333'],
[1, '#FFF']
]
},
borderWidth: 1,
outerRadius: '107%'
}, {
// default background
}, {
backgroundColor: '#DDD',
borderWidth: 0,
outerRadius: '105%',
innerRadius: '103%'
}]
},
// the value axis
yAxis: {
min: 0,
max: 100,
minorTickInterval: 'auto',
minorTickWidth: 1,
minorTickLength: 10,
minorTickPosition: 'inside',
minorTickColor: '#666',
tickPixelInterval: 30,
tickWidth: 2,
tickPosition: 'inside',
tickLength: 10,
tickColor: '#666',
labels: {
step: 2,
rotation: 'auto'
},
title: {
text: 'km/h'
},
plotBands: [{
from: 0,
to: 120,
color: '#55BF3B' // green
}, {
from: 120,
to: 160,
color: '#DDDF0D' // yellow
}, {
from: 160,
to: 200,
color: '#DF5353' // red
}]
},
series: []
};
$.get('data.csv', function(data) {
var series = {
data: [],
name: 'Speed',
tooltip: {
valueSuffix: ' km/h'
}
};
series.data.push(parseFloat(data));
options.series.push(series);
alert("data "+options.series);
var chart = new Highcharts.Chart(options);
});
});
and the csv file is simple
data.csv has only one value 30.
or incase it is
t1,30
t2,40
t3,60
how do i display 3 corresponding speedometers with respective speed.
Your help is greatly appreciated.
Thanks in advance.
In your case data your data (from ajax) is a single string, but you need to split elements and then choose which should be parsed to integer (parseFloat).