Highcharts面积图 - 指定区域颜色

时间:2015-07-29 15:11:23

标签: javascript highcharts

我是编码的新手,我觉得这个答案不应该是非常困难的;然而,我现在已经挣扎了两天左右,所以我正在寻求帮助。

我试图在Highcharts'中指定区域的颜色。 "具有负值的区域图"。我使用的是Highcharts'基本模板,但无法弄清楚如何更改相应区域的颜色。

这是包括我试图指定颜色的JSfiddle;当我这样做时,图表无法运行。 (注意我已经尝试改变" john"系列的颜色。)

http://jsfiddle.net/aoouym2o/

我按照HighCharts'中的说明进行操作。 API,但我无法使其发挥作用。以下是API部分:http://api.highcharts.com/highcharts#plotOptions.area.color

同样,这里的原始代码没有我尝试更改任何颜色:

$(function () {
$('#container').highcharts({
    chart: {
        type: 'area'
    },
    title: {
        text: 'Area chart with negative values'
    },
    xAxis: {
        categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
    },
    credits: {
        enabled: false
    },
    series: [{
        name: 'John',
        data: [5, 3, 4, 7, 2]
    }, {
        name: 'Jane',
        data: [2, -2, -3, 2, 1]
    }, {
        name: 'Joe',
        data: [3, 4, 4, -2, 5]
    }]
});

});

我错过了什么?

4 个答案:

答案 0 :(得分:3)

你完全正确,你在添加颜色设置之前就错过了一个逗号;)

import javafx.application.Application;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;


public class LearnJavafx extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {

        primaryStage.setTitle("JavaFX Welcome");

        GridPane grid = new GridPane();
        grid.setAlignment(Pos.CENTER);
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(25, 25, 25, 25));

        Text scenetitle = new Text("Welcome");
        //scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
        grid.add(scenetitle, 0, 0, 2, 1);

        Label userName = new Label("User Name:");
        grid.add(userName, 0, 1);

        ComboBox userComboBox = new ComboBox();
        grid.add(userComboBox, 1, 1);

        userComboBox.getItems().addAll("jacob.smith@example.com",
                                       "emma.jones@example.com",
                                       "michael.brown@example.com",
                                       "MarioBross@example.com",
                                       "ethan.Williams.Isabella.Johnson.Rodregez@example.com");

        final Text actiontarget = new Text();
        grid.add(actiontarget, 1, 6);

        scenetitle.setId("welcome-text");
        actiontarget.setId("actiontarget");
        Scene scene = new Scene(grid, 300, 275);
        primaryStage.setScene(scene);
        scene.getStylesheets().add
        (LearnJavafx.class.getResource("LearningJavaFx.css").toExternalForm());
        primaryStage.show();
    }

}

Here is a link改编的小提琴。 (更新后的工作版链接)

答案 1 :(得分:2)

您可以通过在每个系列对象中指定颜色来设置图表的颜色:

    series: [{
        name: 'John',
        data: [5, 3, 4, 7, 2],
        color: '#0000FF'
    }, {
        name: 'Jane',
        data: [2, -2, -3, 2, 1],
        color: '#FF0000'
    }, {
        name: 'Joe',
        data: [3, 4, 4, -2, 5],
        color: '#00FF00'
    }]

答案 2 :(得分:1)

只需更改颜色设置:P

INSERT INTO {table}

如果你想改变数字的颜色> 0看 http://www.highcharts.com/docs/chart-concepts/series

答案 3 :(得分:0)

添加选项:

plotOptions: {
    series: {
        lineColor: '#303030'
    }
},