我正在使用JavaScript开发一个Windows应用商店应用程序,其中我以图形方式显示数据(如图表,表格)。在其中一个图表中,我需要显示两个y轴,我有四个系列(两个条形系列和两个系列)条形系列需要绑定到左侧y轴和线系列nee以绑定到右侧y轴。
FYI
就像我需要的那样,非常感谢任何示例代码
答案 0 :(得分:1)
以下是我在其中一个应用程序中使用的代码,希望这对您有所帮助。在下面的代码中,我正在使用ajax调用,我正在解析对json的请求以及我正在使用jqplot图表的数据集。
var barseries = new Array();
var lineseries = new Array();
var barseries2 = new Array();
var lineseries2 = new Array();
var Items = JSON.parse(xhAreaName.responseText);//Parsing the xhr response to json
for (var i = 0; i < Items.GetChartDataResult.length; i++) {
barseries[i] = new Array(2);
lineseries[i] = new Array(2);
barseries2[i] = new Array(2);
lineseries2[i] = new Array(2);
barseries[i][0] = Items.GetChartDataResult[i].AreaName;
barseries[i][1] = Items.GetChartDataResult[i].Actual * 1000;
barseries2[i][0] = Items.GetChartDataResult[i].AreaName;
barseries2[i][1] = Items.GetChartDataResult[i].Budget * 1000;
lineseries[i][0] = Items.GetChartDataResult[i].AreaName;
lineseries[i][1] = Items.GetChartDataResult[i].AttainValue * 100;
lineseries2[i][0] = Items.GetChartDataResult[i].AreaName;
lineseries2[i][1] = Items.GetChartDataResult[i].Target * 100;
$('.jqplot-series-' + i).css('color', '#ffffff');
}
var plot1 = $.jqplot('AreaNameChart', [barseries, lineseries, barseries2, lineseries2], {
series: [{ renderer: $.jqplot.BarRenderer }, { xaxis: 'x2axis', yaxis: 'y2axis' }, { renderer: $.jqplot.BarRenderer }, { xaxis: 'xaxis', yaxis: 'y2axis' }],
seriesDefaults: {
pointLabels: { show: true },
rendererOptions: { fillToZero: true }
},
axesDefaults: {
show: false,
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
rendererOptions: {
drawBaseline: false
}
},
grid: {
backgroundColor: 'transparent',
color: 'White'
},
//legend: {
// show: true,
// placement: 'outsideGrid'
//},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
tickOptions: {
showGridline: false
}
},
x2axis: {
renderer: $.jqplot.CategoryAxisRenderer,
tickOptions: {
showGridline: false,
showTicks: false
},
labelOptions: {
show: true,
},
},
yaxis: {
pad: 1.05,
tickOptions: { formatString: '$%d', showGridline: false, labelPosition: 'middle' }
},
y2axis: {
tickOptions: { formatString: '%d%', showGridline: false, labelPosition: 'middle' }
}
},
seriesColors: ["#1e98e4", "#98b954", "#ffc500", "#695188"],
答案 1 :(得分:0)
以下是有关如何在Yaxis
中使用2 JqPlot
的示例:
JsFiddle Link
$.jqplot.config.enablePlugins = true;
var chartData = [["19-Jan-2012", 2.61], ["20-Jan-2012", 5.00], ["21-Jan-2012", 6.00]];
var chartData1 = [["19-Jan-2012", 20], ["20-Jan-2012", 30], ["21-Jan-2012", 50]];
function PlotChart(chartData, extraDays) {
var plot2 = $.jqplot('chart1', [chartData,chartData1], {
title: 'Mouse Cursor Tracking',
seriesDefaults: {
pointLabels: {
show: true
}
},
series:[
{
yaxis:'yaxis'
},
{
yaxis:'y2axis'
}
],
axes: {
xaxis: {
pad: 1,
// a factor multiplied by the data range on the axis to give the
renderer: $.jqplot.CategoryAxisRenderer,
// renderer to use to draw the axis,
tickOptions: {
formatString: '%b %#d',
formatter: $.jqplot.DateTickFormatter
}
},
yaxis: {
tickOptions: {
formatString: '$%.2f'
}
},
y2axis: {
tickOptions: {
formatString: '$%.2f'
}
}
},
highlighter: {
sizeAdjust: 7.5
},
cursor: {
show: true
}
});
}
PlotChart(chartData, 3);