Javascript 在my API中从图形/高图表更改为贴图/高贴图
我开发了一个脚本,可以在其他服务器的网站中显示在一台服务器上生成的图形(基于客户端发送的一些参数) 看起来像这样:Javascript 在my API中从图形/高图表更改为贴图/高贴图,javascript,php,json,highcharts,Javascript,Php,Json,Highcharts,我开发了一个脚本,可以在其他服务器的网站中显示在一台服务器上生成的图形(基于客户端发送的一些参数) 看起来像这样: function drawGraph(selectedID, selectedCountries, selectedYears, per_capita, graphBorder, graphSource, graphDefinition, graphStyle, graphXAxis, renderToGraph, renderToDescription) {
function drawGraph(selectedID, selectedCountries, selectedYears, per_capita, graphBorder, graphSource, graphDefinition, graphStyle, graphXAxis, renderToGraph, renderToDescription)
{
jQuery(document).ready(function() {
var options = {};
jQuery.getJSON("url here", {selectedCountries: selectedCountries , selectedID: selectedID, selectedYears: selectedYears, per_capita: per_capita, graphBorder: graphBorder, graphSource: graphSource, graphDefinition: graphDefinition, graphStyle: graphStyle, graphXAxis: graphXAxis, renderToGraph: renderToGraph, type: "jsonp"})
.done(function(data)
{
options.chart = data["chart"];
options.tooltip = data["tooltip"];
options.series = data["series"];
options.title = data["title"];
options.subtitle = data["subtitle"];
options.yAxis = data["yAxis"];
options.xAxis = data["xAxis"];
options.legend = data["legend"];
options.exporting = data["exporting"];
options.plotOptions = data["plotOptions"];
options.credits = data["credits"];
var chart = new Highcharts.Chart(options);
}
series : [
{
data : data,
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'iso-2']
}]
var options = {
plotOptions: {
series: {
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'iso-2']
}
}
};
数据[“系列”]包含以下格式的数据:
{"name": "Switzerland",
"iso2": "CH",
"data": [
[1950, 10923],
[1951, 20939],
...
]
}
现在,我想提供将数据显示为地图的可能性,而不是显示图形。在另一个项目中,我实现了这种可能性(但不是作为API),该“series”对象如下所示:
function drawGraph(selectedID, selectedCountries, selectedYears, per_capita, graphBorder, graphSource, graphDefinition, graphStyle, graphXAxis, renderToGraph, renderToDescription)
{
jQuery(document).ready(function() {
var options = {};
jQuery.getJSON("url here", {selectedCountries: selectedCountries , selectedID: selectedID, selectedYears: selectedYears, per_capita: per_capita, graphBorder: graphBorder, graphSource: graphSource, graphDefinition: graphDefinition, graphStyle: graphStyle, graphXAxis: graphXAxis, renderToGraph: renderToGraph, type: "jsonp"})
.done(function(data)
{
options.chart = data["chart"];
options.tooltip = data["tooltip"];
options.series = data["series"];
options.title = data["title"];
options.subtitle = data["subtitle"];
options.yAxis = data["yAxis"];
options.xAxis = data["xAxis"];
options.legend = data["legend"];
options.exporting = data["exporting"];
options.plotOptions = data["plotOptions"];
options.credits = data["credits"];
var chart = new Highcharts.Chart(options);
}
series : [
{
data : data,
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'iso-2']
}]
var options = {
plotOptions: {
series: {
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'iso-2']
}
}
};
现在,很明显,“数据”对象必须看起来有所不同——不是一个国家有多年,而是多个国家有一年。我必须指出的是,不是一张图表,而是一张地图。另外,我需要正确的Javascript/JSON文件
但是现在如何解析系列参数呢?像这样的
options.series = {data: data["series"], mapData: Highcharts.maps['custom/world'], joinBy: ['iso-a2', 'iso-2']};
我应该在“交付端”(也生成数据的php代码)还是在客户端执行此操作
谢谢你的提示。希望我能清楚地知道我想要实现的目标。如果您只想创建一个贴图(总是相同的形状),那么您可以在JS中设置如下选项:
function drawGraph(selectedID, selectedCountries, selectedYears, per_capita, graphBorder, graphSource, graphDefinition, graphStyle, graphXAxis, renderToGraph, renderToDescription)
{
jQuery(document).ready(function() {
var options = {};
jQuery.getJSON("url here", {selectedCountries: selectedCountries , selectedID: selectedID, selectedYears: selectedYears, per_capita: per_capita, graphBorder: graphBorder, graphSource: graphSource, graphDefinition: graphDefinition, graphStyle: graphStyle, graphXAxis: graphXAxis, renderToGraph: renderToGraph, type: "jsonp"})
.done(function(data)
{
options.chart = data["chart"];
options.tooltip = data["tooltip"];
options.series = data["series"];
options.title = data["title"];
options.subtitle = data["subtitle"];
options.yAxis = data["yAxis"];
options.xAxis = data["xAxis"];
options.legend = data["legend"];
options.exporting = data["exporting"];
options.plotOptions = data["plotOptions"];
options.credits = data["credits"];
var chart = new Highcharts.Chart(options);
}
series : [
{
data : data,
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'iso-2']
}]
var options = {
plotOptions: {
series: {
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'iso-2']
}
}
};
现在,您的API根本不会改变:
options.series = data["series"];