Search code examples
amchartsamcharts4

How can I draw sparkline graphs in two colors


I would like to draw the line of sparkline in two colors depends if the value is under a reference value, and in another color if the value is above the same reference value.

const conf: EvolutionChartConfiguration<LaborGridAnalysis> = {
        dateField: 'Date',
        hideGrid: true,
        hideTooltip: true,
        hideLabel: true,
        seriesGroups: [
            {
                series: [
                    {
                    field: field,
                    type: type,
                    color: colorSerie,
                    label: label,
                    shape: 'line',
                    shownOnScrollbar: false,
                    hideLineBullets: true
                }]
            }
        ]
    };
    return conf;

Thanks


Solution

  • Gotcha. In this case you would have a code like this:

    // This set line color to green
    series.stroke = am4core.color("#00ff00");
    
    // This set line color to red above 100
    var range = valueAxis.createSeriesRange(series);
    range.value = 100;
    range.endValue = 100000;
    range.contents.stroke = am4core.color("#ff0000");