parsing failed because a } isnt put in? - lua
Setting up a fivem server and trying to get esx_policejobs to work after putting in custom job_grades. Have gotten an error and have been stuck for hours, I don't know if I'm missing something here or not?
Theres also a console line that says stack traceback to a different .lua file, so could that end up being the problem in there instead of the actual config file?
Have looked over and over the config and honestly cant find the problem
recruit = {
{ weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
{ weapon = 'WEAPON_NIGHTSTICK', price = 0 },
{ weapon = 'WEAPON_STUNGUN', price = 1500 },
{ weapon = 'WEAPON_FLASHLIGHT', price = 80 },
},
private = {
{ weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
{ weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
{ weapon = 'WEAPON_NIGHTSTICK', price = 0 },
{ weapon = 'WEAPON_STUNGUN', price = 500 },
{ weapon = 'WEAPON_FLASHLIGHT', price = 0 },
},
private-first-class = {
{ weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
{ weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
{ weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
{ weapon = 'WEAPON_NIGHTSTICK', price = 0 },
{ weapon = 'WEAPON_STUNGUN', price = 500 },
{ weapon = 'WEAPON_FLASHLIGHT', price = 0 }
},
sergeant = {
{ weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
{ weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
{ weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
{ weapon = 'WEAPON_NIGHTSTICK', price = 0 },
{ weapon = 'WEAPON_STUNGUN', price = 500 },
{ weapon = 'WEAPON_FLASHLIGHT', price = 0 },
},
lieutenant = {
{ weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
{ weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
{ weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
{ weapon = 'WEAPON_NIGHTSTICK', price = 0 },
{ weapon = 'WEAPON_STUNGUN', price = 500 },
{ weapon = 'WEAPON_FLASHLIGHT', price = 0 },
},
captain = {
{ weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
{ weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
{ weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
{ weapon = 'WEAPON_NIGHTSTICK', price = 0 },
{ weapon = 'WEAPON_STUNGUN', price = 500 },
{ weapon = 'WEAPON_FLASHLIGHT', price = 0 },
},
inspector = {
{ weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
{ weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
{ weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
{ weapon = 'WEAPON_NIGHTSTICK', price = 0 },
{ weapon = 'WEAPON_STUNGUN', price = 500 },
{ weapon = 'WEAPON_FLASHLIGHT', price = 0 },
},
deputy-chief = {
{ weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
{ weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
{ weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
{ weapon = 'WEAPON_NIGHTSTICK', price = 0 },
{ weapon = 'WEAPON_STUNGUN', price = 500 },
{ weapon = 'WEAPON_FLASHLIGHT', price = 0 },
},
assistant-chief = {
{ weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
{ weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
{ weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
{ weapon = 'WEAPON_NIGHTSTICK', price = 0 },
{ weapon = 'WEAPON_STUNGUN', price = 500 },
{ weapon = 'WEAPON_FLASHLIGHT', price = 0 },
},
chief-of-police = {
{ weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
{ weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
{ weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
{ weapon = 'WEAPON_NIGHTSTICK', price = 0 },
{ weapon = 'WEAPON_STUNGUN', price = 500 },
{ weapon = 'WEAPON_FLASHLIGHT', price = 0 },
},
}
Shouldnt be any config errors
Error in console:
Failed to load script config.lua.
Error loading script server/main.lua in resource esx_policejob: #esx_policejob/server/main.lua:5: attempt to index a nil value (global 'Config')
stack traceback:
#esx_policejob/server/main.lua:5: in main chunk```
The problem is with the dashes in the table key names. The manual does give a hint about the form of the table constructor:
A field of the form name = exp is equivalent to ["name"] = exp.
A name must be:
Names (also called identifiers) in Lua can be any string of letters, digits, and underscores, not beginning with a digit and not being a reserved word. Identifiers are used to name variables, table fields, and labels.
This means you have to use the second form of the table constructor ["name"] = exp for anything that isn't valid identifier.
['chief-of-police'] = {
{ weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
{ weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
{ weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
{ weapon = 'WEAPON_NIGHTSTICK', price = 0 },
{ weapon = 'WEAPON_STUNGUN', price = 500 },
{ weapon = 'WEAPON_FLASHLIGHT', price = 0 },
}
Error in your code "private" reserved word:
>>>>private = {
{ weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
{ weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
{ weapon = 'WEAPON_NIGHTSTICK', price = 0 },
{ weapon = 'WEAPON_STUNGUN', price = 500 },
{ weapon = 'WEAPON_FLASHLIGHT', price = 0 },
},
table must be constructed
myTable = {}
after table exists, you can define key:
myTable["some.key"] = {}
if you nead sub-key, next step will be:
myTable["some.key"]["sub.key"] = {}
myTable["some.key"]["sub.key"]["value_1"] = "123"
myTable["some.key"]["sub.key"]["value_2"] = "456"
at the end, you can use trick:
local myTables = {}
myTables["table_name"] = myTable
Related
Show Dyanmic Multiple Lines on Chart in Swift
I am working on app in which I have to show the json data on charts which is a swift framework I am using. I am able to show the data correctly on the charts but can't able to make the function dynamic. So that any n numbers of charts I can show on the LineChart graph.This is the library I am using https://github.com/danielgindi/Charts . This is the function I am using to show the datas on graph func newLineChartValue(carbonLineChartValue: [LineChartValue]) { for value in self.carbonLineChartValue { self.zoneNames.append(value.Zone_name!) self.allValueArray.append(value.value_array!) self.colors.append(value.zone_color!) } var lineChartEntry1 = [ChartDataEntry]() var lineChartEntry2 = [ChartDataEntry]() var lineChartEntry3 = [ChartDataEntry]() let firstLineArray = allValueArray[0] print("FirstLine Data: \(firstLineArray)") var timeLbl = [String]() var valueOne = [Double]() for lbl in firstLineArray { timeLbl.append(lbl.label!) valueOne.append(lbl.value!) print("Time1:-> \(timeLbl)") print("Value1:-> \(valueOne)") } for i in 0..<timeLbl.count { lineChartEntry1.append(ChartDataEntry(x: Double(i), y: Double(valueOne[i]))) } let set1 = LineChartDataSet(entries: lineChartEntry1, label: "") set1.axisDependency = .left set1.mode = .cubicBezier set1.setColor(UIColor.init(hex: colors[0])) set1.fillColor = UIColor.init(hex: colors[0]) set1.setCircleColor(UIColor.init(hex: colors[0])) set1.lineWidth = 4 set1.circleRadius = 4 set1.fillAlpha = 65/255 set1.drawCircleHoleEnabled = false let secondLineArray = allValueArray[1] var valueTwo = [Double]() for value in secondLineArray { valueTwo.append(value.value!) print("Value2:-> \(valueTwo)") } for i in 0..<valueTwo.count { lineChartEntry2.append(ChartDataEntry(x: Double(i), y: Double(valueTwo[i]))) } let set2 = LineChartDataSet(entries: lineChartEntry2, label: "") set2.mode = .cubicBezier set2.axisDependency = .left set2.setColor(UIColor.init(hex: colors[1])) set2.fillColor = UIColor.init(hex: colors[1]) set2.setCircleColor(UIColor.init(hex: colors[1])) set2.lineWidth = 4 set2.circleRadius = 4 set2.fillAlpha = 65/255 set2.drawCircleHoleEnabled = false let thirdLine = allValueArray[2] var valueThree = [Double]() for value in thirdLine { valueThree.append(value.value!) print("Value3:-> \(valueThree)") } for i in 0..<valueThree.count { lineChartEntry3.append(ChartDataEntry(x: Double(i), y: Double(valueThree[i]))) } let line3 = LineChartDataSet(entries: lineChartEntry3, label: "") line3.axisDependency = .left line3.mode = .cubicBezier line3.setColor(UIColor.init(hex: colors[2])) line3.fillColor = UIColor.init(hex: colors[2]) line3.setCircleColor(UIColor.init(hex: colors[2])) line3.lineWidth = 4 line3.circleRadius = 4 line3.fillAlpha = 65/255 line3.drawCircleHoleEnabled = false let lineChartData = LineChartData(dataSets: [set1,set2,line3]) lineChartData.setDrawValues(false) lineChartView.xAxis.labelPosition = .bottom self.lineChartView.xAxis.valueFormatter = DefaultAxisValueFormatter(block: {(index, _) in return timeLbl[Int(index)] }) self.lineChartView.data = lineChartData } This is the Struct for LineChartValue struct LineChartValue: Codable { var Zone_name: String? var zone_color: String? var value_array: [LineChartValueArray]? } JSON Coming from Server { "show_Zone": true "Zone_name": "Zone Sales", "zone_color": "#c69f49", "value_array": [ { "label": "01:00 AM", "value": 0 }, { "label": "02:00 AM", "value": 0 }, { "label": "03:00 AM", "value": 0 }, { "label": "04:00 AM", "value": 0 }, { "label": "05:00 AM", "value": 0 }, { "label": "06:00 AM", "value": 0 }, { "label": "07:00 AM", "value": 0 }, { "label": "08:00 AM", "value": 0 }, { "label": "09:00 AM", "value": 0 }, { "label": "10:00 AM", "value": 0 }, { "label": "11:00 AM", "value": 0 }, { "label": "12:00 AM", "value": 0 }, { "label": "01:00 PM", "value": 0 }, { "label": "02:00 PM", "value": 0 }, { "label": "03:00 PM", "value": 0 }, { "label": "04:00 PM", "value": 0 }, { "label": "05:00 PM", "value": 0 }, { "label": "06:00 PM", "value": 0 }, { "label": "07:00 PM", "value": 0 }, { "label": "08:00 PM", "value": 0 }, { "label": "09:00 PM", "value": 0 }, { "label": "10:00 PM", "value": 0 }, { "label": "11:00 PM", "value": 0 }, { "label": "12:00 PM", "value": 0 } ] }, I want to make this function dynamic so I can show n numbers of lines on graph.
Here is your code reduced to use a loop over carbonLineChartValue instead of hardcoding accessing the first 3 elements of the array. The first iteration of the array populates the timeLbl array to replicate you populating that array from the first element. I've also removed all uses of ! to avoid possible crashes from force-unwrapping nil values. Since I do not have your charts library nor several other structures referenced in your code I am not able to verify that this code will compile as written. There may be a mistake or two here from trying to translate your original code. But the general idea should be valid. I also don't show the initial for loop where you populate self.zoneNames, self.allValueArray, and self.colors since it's not needed for this function. Put it back in if you need those results for other uses. func newLineChartValue(carbonLineChartValue: [LineChartValue]) { var dataSets = [LineChartDataSet]() var timeLbl = [String]() for (index, chartValue) in carbonLineChartValue.enumerated() { guard let zoneName = chartValue.Zone_name, let zoneColor = chartValue.zone_color, let lineArray = chartValue.value_array else { continue } // Skip this one if it's not to be shown if chartValue.show_Zone == false { continue } let lineChartEntry = [ChartDataEntry]() if index == 0 { timeLbl = lineArray.compactMap { $0.label } } for (index, value) in lineArray.enumerated() { if let y = value.value { lineChartEntry.append(ChartDataEntry(x: Double(index), y: y)) } } let set = LineChartDataSet(entries: lineChartEntry, label: "") set.mode = .cubicBezier set.axisDependency = .left set.setColor(UIColor(hex: zoneColor)) set.fillColor = UIColor(hex: zoneColor) set.setCircleColor(UIColor(hex: zoneColor)) set.lineWidth = 4 set.circleRadius = 4 set.fillAlpha = 65/255 set.drawCircleHoleEnabled = false dataSets.append(set) } let lineChartData = LineChartData(dataSets: dataSets) lineChartData.setDrawValues(false) lineChartView.xAxis.labelPosition = .bottom self.lineChartView.xAxis.valueFormatter = DefaultAxisValueFormatter(block: {(index, _) in return timeLbl[Int(index)] }) self.lineChartView.data = lineChartData }
Kong -- How do I write my entity_checks for array #6989
Summary I am developing my own rate-limiting plugins based on the official one. The origin schema looks like: fields = { { config = { type = "record", fields = { { second = { type = "number", gt = 0 }, }, { minute = { type = "number", gt = 0 }, }, } ... }, }, My schema looks like: { config = { type = "record", fields = { { plans = { type = "array", elements = { type = "record", fields = { { second = { type = "number", gt = 0 }, }, { minute = { type = "number", gt = 0 }, }, } }, },}, }, custom_validator = validate_periods_order, }, }, You can see that the first field is called "plans" and it's type is an array which means I will have config.plans[0].second, config.plans[0].second, ... and the original one was config.second Below is the origin entity_checks function of rate-limiting, I have no idea how to re-write it to match my schema since it changed from simple record type to array type entity_checks = { { at_least_one_of = { "config.second", "config.minute", "config.hour", "config.day", "config.month", "config.year" } }, { conditional = { if_field = "config.policy", if_match = { eq = "config.redis" }, then_field = "config.redis_host", then_match = { required = true }, } }, { conditional = { if_field = "config.policy", if_match = { eq = "config.redis" }, then_field = "config.redis_port", then_match = { required = true }, } }, { conditional = { if_field = "config.policy", if_match = { eq = "config.redis" }, then_field = "config.redis_timeout", then_match = { required = true }, } }, },
Create a local schema for plan local plan_schema = { type = "record", fields = { { second = { type = "number", gt = 0 }, }, { minute = { type = "number", gt = 0 }, }, }, custom_validator = validate_periods_order, entity_checks = { { at_least_one_of = { "second", "minute" } }, } } Then on your config set plans as an array of plan return { name = plugin_name, fields = { { consumer = typedefs.no_consumer }, { protocols = typedefs.protocols_http }, { config = { type = "record", fields = { { plans = { type = "array", elements = plan_schema , } }, } }, }, }
HighStock: Trend jumping out of Chart Area on zooming with zoomType='xy' or zoomType='y'
I am working with HighCharts (Version:^5.0.14) and React(react:^15.0.1, react-dom:^15.0.1). I am facing an issue with HighStock Chart Zooming. With the zoomType = 'xy' or zoomType='y', the zoomed HighStock trend jumps of the X-Axis and Y-Axis. Below is the picture. However if Zooming type zoomType = 'X' no issues. The problem is faced when including zoomType = 'y' Below is the Code: import React from 'react'; import highcharts from 'highcharts/highstock'; export default class Chart extends React.Component { constructor (props) { super(props); this.state = { chartName: `chart${this.props.chartNum}` }; } componentDidMount () { let chartOptions = {}; chartOptions = { rangeSelector: {enabled: false }, credits: { enabled: false }, tooltip: { pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y:.2f}</b> <br/>' }, navigator: { enabled: false }, scrollbar: { enabled: false }, plotOptions:{ series:{ turboThreshold:5000//set it to a larger threshold, it is by default to 1000, } }, xAxis:{ type: 'dateTime', minRange:3600000, events:{ setExtremes:function(event){ this.min=event.min; this.max=event.max; } } }, yAxis: { offset: 15, labels: { align: 'center', x: -5, y: 0 }, opposite:false, showLastLabel: true, min: this.dataMin, max: this.dataMax, events:{ setExtremes:function(events){ console.log("Card::YAxis::setExtremes::events.min and events.max = " + events.min +", "+ events.max); this.dataMin = events.min; this.dataMax = events.Max; this.min = events.min; this.max = events.max; } }, tickPositioner: function () { var positions; var Maxdata = this.max; var MinData = this.min; if(ticksData != null){ positions = ticksData; }else{ positions = []; var tick = Math.floor(this.min); if(this.min == this.max){ positions.push(this.min); }else{ if (this.max !== null && this.min !== null) { Maxdata = Maxdata.toFixed(2); MinData = MinData.toFixed(2); tick = parseFloat(MinData); var increment = (Maxdata - MinData)/5; increment=increment.toFixed(2); for (tick; tick-increment<= Maxdata; tick=(parseFloat(increment)+parseFloat(tick)).toFixed(2)) { if(positions.includes(tick)){ break; } else{ positions.push(tick); } } }else{ positions = [0]; } } } return positions; } } }; chartOptions.chart = { renderTo: document.getElementById(this.state.chartName), zoomType: 'xy', spacingBottom: 35, resetZoomButton: { position: { align: 'right', // by default verticalAlign: 'bottom', // by default x: 8, y: 20 } }, events:{ redraw: function(){ var serie1 = this.series[0], yExtremes = this.yAxis[0].getExtremes(); var yMin = yExtremes.min; var yMax = yExtremes.max; var dataSet = serie1.data; var zoomedDataSet= []; var dataGroup; if(dataSet != undefined && dataSet != null){ for(var i=0; i<dataSet.length; i++) { if(dataSet[i] != undefined){ dataGroup = dataSet[i]; if(dataGroup[1] > yMin && dataGroup[1]< yMax){ zoomedDataSet.push(dataGroup); } } } serie1.data = zoomedDataSet; } } } }; // Generate chart. this.generateChart(this.props.data, chartOptions); } componentWillUpdate (nextProps) { let chartOptions = {}; chartOptions = { rangeSelector: {enabled: false }, credits: { enabled: false }, tooltip: { pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y:.2f}</b> <br/>' }, navigator: { enabled: false }, scrollbar: { enabled: false }, plotOptions:{ series:{ turboThreshold:5000//set it to a larger threshold, it is by default to 1000, } }, xAxis:{ type: 'dateTime', minRange:3600000, events:{ setExtremes:function(event){ this.min=event.min; this.max=event.max; } } }, yAxis: { offset: 15, labels: { align: 'center', x: -5, y: 0 }, opposite:false, showLastLabel: true, min: this.dataMin, max: this.dataMax, events:{ setExtremes:function(events){ console.log("Card::YAxis::setExtremes::events.min and events.max = " + events.min +", "+ events.max); this.dataMin = events.min; this.dataMax = events.Max; this.min = events.min; this.max = events.max; } }, tickPositioner: function () { var positions; var Maxdata = this.max; var MinData = this.min; if(ticksData != null){ positions = ticksData; }else{ positions = []; var tick = Math.floor(this.min); if(this.min == this.max){ positions.push(this.min); }else{ if (this.max !== null && this.min !== null) { Maxdata = Maxdata.toFixed(2); MinData = MinData.toFixed(2); tick = parseFloat(MinData); var increment = (Maxdata - MinData)/5; increment=increment.toFixed(2); for (tick; tick-increment<= Maxdata; tick=(parseFloat(increment)+parseFloat(tick)).toFixed(2)) { if(positions.includes(tick)){ break; } else{ positions.push(tick); } } }else{ positions = [0]; } } } return positions; } } }; chartOptions.chart = { renderTo: document.getElementById(this.state.chartName), zoomType: 'xy', spacingBottom:35, resetZoomButton: { position: { align: 'right', // by default verticalAlign: 'bottom', // by default x: 8, y: 20 } }, events:{ redraw: function(){ var serie1 = this.series[0], yExtremes = this.yAxis[0].getExtremes(), var yMin = yExtremes.min; var yMax = yExtremes.max; var dataSet = serie1.data; var zoomedDataSet= []; if(dataSet != undefined && dataSet != null ){ for(var i=0; i<dataSet.length; i++) { if(dataSet[i] != undefined){ dataGroup = dataSet[i]; if(dataGroup[1] >= yMin && dataGroup[1]<=yMax && dataGroup[0] >= xMin && dataGroup[0]<= xMax){ zoomedDataSet.push(dataGroup); } } } serie1.data = zoomedDataSet; } } } }; this.generateChart(nextProps.data, chartOptions); } generateChart (data, chartOptions) { chartOptions.series = [ { name: this.props.title, type: this.props.status ? 'area' : 'line', data: data, clip: false } ]; let chart = new highcharts.StockChart(chartOptions); } render () { const selfStyle = { height: '200px' }; return ( <div className="med-chart col-md-9" id={this.state.chartName} style={selfStyle}> </div> ); } } I have setExtremes set with event Min and Max values for Y-Axis, but it does not help. If any of you have faced a similar issue, request to share your approach to resolve this problem. Greatly appreciate your time in reading the post and your valuable inputs in advance.
HightCharts Realtime line error
HightCharts realtime line error Who had the following problems?
var loadChart = function () { $.getJSON('data.json', function (json) { var index = 0; var getData = function (index, type) { var result = null; if (type != undefined) { result = parseInt(json[index][type]); } else { result = json[index]; } return result; }; var getSeriesData = function () { // 结构 var JJData = [], PCData = [], PhoneData = [], item; var time = (new Date()).getTime(); for (var i = -179; i <= 0; ++i) { item = json[index++]; JJData.push({ x: time + i * 2000, y: parseInt(item.JJ) }); PCData.push({ x: time + i * 2000, y: parseInt(item.PC) }); PhoneData.push({ x: time + i * 2000, y: parseInt(item.Phone) }); } var result = [{ name: "JJ", data: JJData }, { name: "PC", data: PCData }, { name: "Phone", data: PhoneData }]; return result; }; chart = new Highcharts.Chart({ chart: { renderTo: 'container1', type: 'spline', //spline backgroundColor: 'rgba(202, 202, 202, 0.2)', animation: Highcharts.svg, // don't animate in old IE //marginRight: 10, events: { load: function () { var series = this.series; loadMinuteData = function () { if (!minuteFlag) { clearInterval(setMinuteInter); return false; } var x = (new Date()).getTime(); // current time var result = getData(index++); // 第三个参数为true,移除最开始的数据 //console.log("minute"); //console.log(series[0]); //alert(series[0]); series[0].addPoint([x, parseInt(result.JJ)], true, true); series[1].addPoint([x, parseInt(result.PC)], true, true); series[2].addPoint([x, parseInt(result.Phone)], true, true); }; var setMinuteInter = setInterval(loadMinuteData, 2000); } } }, title: { text: '实时在线人数' }, xAxis: [{ type: 'datetime', tickPixelInterval: 60 }], yAxis: { title: { text: '人数' }, plotLines: [{ value: 0, width: 1, color: '#808080' }] }, plotOptions: { spline: { marker: { enabled: false } } }, tooltip: { formatter: function () { return '<b>' + this.series.name + '</b><br/>' + Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' + Highcharts.numberFormat(this.y, 2); } }, legend: { enabled: true }, exporting: { enabled: false }, series: getSeriesData() }); }); }
Highcharts setExtremes overflow issue
I have a Highcharts column graph with 10 series on the x axis. http://qaa.balcroft.com/images/chart1.png I want to allow the user to zoom in so I added a button to setExtremes: $('#zoomInButton').click(function () { var chart = $('#container').highcharts(); chart.xAxis[0].setExtremes(4, 9); }); However this causes the graph to overflow into the y axis title area on the left hand side. http://qaa.balcroft.com/images/chart2.png I've tried amending xAxis.minRange and yAxis.overflow but neither fixes the problem. Any suggestions? The function to create the graph is function inialiseGraphOnLoad(strOrgCode, strLevelCode, currentLevel, strTeamName){ var jsonMimeType = "application/json;charset=UTF-8"; $.ajax({ type: "POST", url: "ajax/getStaffOnLoad.php", cache: false, data: {org: strOrgCode, levelcode: strLevelCode, level: currentLevel}, beforeSend: function(x) { if(x && x.overrideMimeType) { x.overrideMimeType(jsonMimeType); } }, dataType: 'json', success: function(dataDepts){ //Create array of employee names chartWidth = 0; maxZoom = 0; var listDepts = []; for (var i = 0; i < dataDepts.employees.length; i++) { chartWidth = chartWidth + 250; maxZoom = maxZoom + 1; var arrayEmployee = dataDepts.employees[i].name; var splitResult = arrayEmployee.split("||"); var strEmployeeCode=splitResult[0]; var strEmployeeName=splitResult[1]; var employeeURL = serverURL + strEmployeeCode + '">' + strEmployeeName + '</a>'; listDepts.push(employeeURL); } var mainPageWidth = $('#staffMainPage').width(); if(chartWidth > mainPageWidth){ chartWidth = mainPageWidth; }else if(chartWidth < 500){ chartWidth = 500; } $('#hid_lastPage').val(maxZoom); //Create series array var seriesArray = []; for (var i = 0; i < dataDepts.groups.length; i++) { seriesArray.push({ name : dataDepts.groups[i].name, dataLabels: { enabled: true, rotation: -90, color: '#424242', align: 'right', x: 4, y: 10, style: { fontFamily: 'Verdana, sans-serif' }, formatter:function(){ if(this.y > 0){ return this.y; } } }, color : dataDepts.groups[i].colour, data : [] }); for (var j = 0; j < dataDepts.employees.length; j++) { if(i == 0){ seriesArray[i].data.push(dataDepts.employees[j].rating1); }else if(i == 1){ seriesArray[i].data.push(dataDepts.employees[j].rating2); }else if(i == 2){ seriesArray[i].data.push(dataDepts.employees[j].rating3); }else if(i == 3){ seriesArray[i].data.push(dataDepts.employees[j].rating4); }else if(i == 4){ seriesArray[i].data.push(dataDepts.employees[j].rating5); }else if(i == 5){ seriesArray[i].data.push(dataDepts.employees[j].rating6); }else if(i == 6){ seriesArray[i].data.push(dataDepts.employees[j].rating7); }else if(i == 7){ seriesArray[i].data.push(dataDepts.employees[j].rating8); }else if(i == 8){ seriesArray[i].data.push(dataDepts.employees[j].rating9); }else if(i == 9){ seriesArray[i].data.push(dataDepts.employees[j].rating10); }else if(i == 10){ seriesArray[i].data.push(dataDepts.employees[j].rating11); }else if(i == 11){ seriesArray[i].data.push(dataDepts.employees[j].rating12); }else if(i == 12){ seriesArray[i].data.push(dataDepts.employees[j].rating13); }else if(i == 13){ seriesArray[i].data.push(dataDepts.employees[j].rating14); }else if(i == 14){ seriesArray[i].data.push(dataDepts.employees[j].rating15); } } } // Set up the chart var chart = new Highcharts.Chart({ chart: { renderTo: 'container', type: 'column', width: chartWidth, height: 550, marginBottom: 100, margin: 80, options3d: { enabled: true, alpha: 5, beta: 10, depth: 50, viewDistance: 25 } }, title: { text: strTeamName }, subtitle: { text: 'Quality Rating By Employee' }, xAxis: { categories: listDepts, useHTML: true, minRange: 5, title: { text: '<br>(click an employee name for more detail)', style: { color: '#6E6E6E', fontSize: '1em', fontFamily: 'Verdana, sans-serif' } } }, yAxis: { min: 0, title: { text: 'Quality Rating (%)', align: 'high' }, labels: { overflow: 'justify' } }, tooltip: { valueSuffix: ' %' }, scrollbar: { enabled: true }, plotOptions: { column: { depth: 25 }, bar: { dataLabels: { enabled: true } } }, series:seriesArray }); } }); }