由于某种原因,我无法设置以文字形式创建的Javascript对象的正确性。 使用PHP编写Javascript代码。第一个图表对象chartObject1正确显示,但第二个图表chartObject2不显示标题,因为我试图在文字定义之外设置标题文本属性。
为什么不让我使用chartObject2.title.text = "chart2";
??
<?php
$chart_text = <<<EOD
<script type="text/javascript">
var chartObject1 = Object;
$(document).ready(function(){
chartObject1 = new Highcharts.Chart({
chart: {
renderTo: 'chart1',
type: 'bar'
},
title: {
text: 'chart1'
},
xAxis: {
categories: ['Apples', 'Bananas', 'Oranges']
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
series: [{
name: 'Jane',
data: [1, 0, 4]},
{
name: 'John',
data: [5, 7, 3]}]
});
});
</script>
EOD;
print ($chart_text);
$chart_text = <<<EOD
<script type="text/javascript">
var chartObject2 = Object;
$(document).ready(function(){
chartObject2 = new Highcharts.Chart({
chart: {
renderTo: 'chart2',
type: 'bar'
},
xAxis: {
categories: ['Spiders', 'Grasshoppers', 'Scorpions']
},
yAxis: {
title: {
text: 'Bugs eaten'
}
},
series: [{
name: 'Jane',
data: [1, 0, 4]},
{
name: 'John',
data: [5, 7, 3]}]
});
chartObject2.title.text = "chart2";
});
</script>
EOD;
print ($chart_text);
?>
答案 0 :(得分:0)
因为它是一个Highcharts对象,你需要使用它们的api来改变文本。 像这样:
chartObject2.setTitle({text: "chart2"});