AmChart: Setting a Color Line for a Graphic Failure

I am trying to get a multi-line chart using StockChart. At first I tried without any special settings for color properties, but the lines that I had were orange. So I tried to make the graphics have different colors using the "colors" array in the StockPanel class. This works to set legendColor, but with an error when setting line colors.

Did I do something stupid? How can I initiate automatic color assignment?

Here is my code:

var stockPanel1 = new AmCharts.StockPanel();
stockPanel1.showCategoryAxis = true;

var graph1;

$.each($("#building-select").val(), function(index, value) {
    graph1 = new AmCharts.StockGraph();
    graph1.valueField = buildingNames[value];
    graph1.legendColor = stockPanel1.colors[index]; // this works
    graph1.lineColor = stockPanel1.colors[index];   // this does not work
    graph1.title = buildingNames[value];
    graph1.bulletBorderColor = "#FFFFFF";
    graph1.bulletBorderAlpha = 1;                                       
    graph1.balloonText = buildingNames[value] + ":<b>$[[value]]</b>";
    stockPanel1.addStockGraph(graph1);
});

This is what I get from the code. Note that the colors of the legends are set accordingly, but the colors of the lines are still orange. Legend colors are fine, but line colors are all orange

Update:

I replaced the creation code with the JSON format by adding the configuration "useDataSetColors: false". It works for the start line.

stockGraphs: [{
    id: "g1",
    valueField: $("#type-select").val(),
    comparable: true,
    useDataSetColors: false,
    lineColor: Colors[0],    // this works
    compareField: $("#type-select").val(),
    balloonText: "[[title]]:<b>$[[value]]</b>",
    compareGraphBalloonText: "[[title]]:<b>$[[value]]</b>"
}]

:

$.each($(this).val(), function(index, value) {
    chartDataSets[value].color = Colors[index];
    if (index == 0) {
        chart.mainDataSet = chartDataSets[value];
    } else {
        chartDataSets[value].compared = true;
    }
});

, - , , , , .

, ? , amCharts, , StockCharts.

+4
1

graph.useDataSetColors = false;

+3

Source: https://habr.com/ru/post/1530209/


All Articles