gpt4 book ai didi

javascript - AmChart 不显示第二个 y 轴

转载 作者:行者123 更新时间:2023-11-29 18:16:14 26 4
gpt4 key购买 nike

我的任务是在一个图表中显示 2 个图表,因此我需要两个 y 轴来表示图表。一个轴将在左侧,另一个在右侧。

我的问题是只显示一个 y 轴。当我使用 amCharts 时,我注意到一个问题,可见的 y 轴有一个名为 allLabels 的数组,其中包含元素,但第二个 y 轴没有,但我不知道什么填充了该数组属性。

代码:

function addconsumerUsageGraph(consumerUsageGraph) {
//You can ignore this
if (consumerUsageGraph.graphs.length == 2)
{
var gr1 = consumerUsageGraph.graphs[0];
var gr2 = consumerUsageGraph.graphs[1];
consumerUsageGraph.removeGraph(gr1);
consumerUsageGraph.removeGraph(gr2);
}

if (consumerUsageGraph.graphs.length == 1) {
var gr1 = consumerUsageGraph.graphs[0];
consumerUsageGraph.removeGraph(gr1);
}

//I add the two yAxis here:
var yAxis1 = new AmCharts.ValueAxis();
yAxis1.position = "left";

var yAxis2 = new AmCharts.ValueAxis();
yAxis2.position = "right"; // set this to "right" if you want it on the right

//Adding the value axis to the whole graph
consumerUsageGraph.addValueAxis(yAxis1);
consumerUsageGraph.addValueAxis(yAxis2);

var graph = new AmCharts.AmGraph();
graph.valueField = "value";
graph.type = "column";
graph.title = "Usage";
graph.lineAlpha = 1;
graph.fillAlphas = 0.75;

consumerUsageGraph.addGraph(graph);

var graph2 = new AmCharts.AmGraph();
graph2.valueField = "cost";
graph2.type = "line";
graph2.lineAlpha = 1;
graph2.title = "Cost";
graph2.lineColor = graphColour;
graph2.bullet = "round";
graph2.bulletAlpha = 0.5;
graph2.bulletBorderAlpha = 0.8;

//Assigning the second yAxis to the second graph
graph2.valueAxes = yAxis2;


consumerUsageGraph.addGraph(graph2);

//consumerUsageGraph.write("chartdiv");

var legend = new AmCharts.AmLegend();
legend.marginBottom = -10;
legend.useGraphSettings = true;
consumerUsageGraph.addLegend(legend);
}

图表现在的样子:

enter image description here

最佳答案

图没有属性 valueAxes,请改用 valueAxis:

graph2.valueAxis = yAxis2;

关于javascript - AmChart 不显示第二个 y 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23132629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com