KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Change StackedColumn sorting #2049

Closed Peter Wendel opened this topic on on Apr 29, 2021 - 13 comments

Peter Wendel commented on Apr 29, 2021

Hello!

I configured three StackedColumn-Charts in exactly the same way. It works fine despite of one point:

Due to different values the alingment of the stacked columns changes:

For example you see in chart one (top to bottom) value1, value2. value3 In the next one you may see: value3, value1, value2 and in th third value2,value3,value1

All values are in the configured color, but they change places. How can I fix it to one solid order?

Sebastian Morales commented on May 4, 2021

Peter, would you mind attaching a screenshot for us to better understand the problem? Tks,

Peter Wendel commented on May 4, 2021

As you can see "grey" and "orange" changed places in the column. The specialised unit wants me to keep the order...

Sebastian Morales commented on May 4, 2021

It's a pity we can't see your picture yet. Pls upload it here or link to its url elsewhere. Tks,

Peter Wendel commented on May 4, 2021

Fixed...

KoolReport commented on May 4, 2021

It could be because the second group "Durchs..." does not have Max. moglicher... and Abzug Ziele.. data, or those data is equal to 0. Could you please check.

Peter Wendel commented on May 4, 2021

Please look at the tooltip-table in the second picture... all values are > 0 .

How can I force the order ? (matching question for the date, #MayThe4th)

KoolReport commented on May 4, 2021

The tooltip showing values of the first group (Verordnung...). Could you please check data of second group "Durchs..."

Peter Wendel commented on May 4, 2021

We only talk about the left stacked column. Only this column needs to be sorted.

Yes in the right column two of the values are 0.

KoolReport commented on May 4, 2021

I understand now. So basically it is from 2 different charts and you want to keep the order of legend (and the blocks) to be the same in two charts. Could you please post the code of two chart. I would like to see.

Sebastian Morales commented on May 4, 2021

Pls try setting your color scheme directly like this:

    chartjs\ColumnChart::create(array(
                "name" => "chartjs_columnchart",
                "dataStore" => $this->dataStore('myDatastore'),
                "colorScheme" => [
                    "#ff6384", //only use hex color here
                    "#ff9f40",
                    "#ffcd56",
                    "#4bc0c0",
                    "#36a2eb",
                    "#9966ff",
                    "#c9cbcf",
                ],
                ...

Let us know it works for you. Tks,

Peter Wendel commented on May 4, 2021

Okay...

<?php

use koolreport\d3\ColumnChart;

$data =
    [
        [
            'category' => 'Verordnungskosten',
            'Erreichte Ziele' => $this->dataStore('ZqData1')->sum('erf_bereinigung'),
            'Alle Ziele erreicht' => $this->dataStore('ZqData1')->sum('opt_bereinigung'),
            'VO-Kosten' => $this->dataStore('PvbDwv')->sum('vk') - $this->dataStore('ZqData1')->sum('erf_bereinigung') - $this->dataStore('ZqData1')->sum('opt_bereinigung'),

        ],
        [
            'category' => 'Durchschnittswertevolumen',
            'VO-Kosten' => $this->dataStore('PvbDwv')->sum('dwv'),
            'Erreichte Ziele' => 0,
            'Alle Ziele erreicht' => 0,

        ],

    ];

ColumnChart::create([
    'dataSource' => $data,
    'columns' => [
        'category',
        'VO-Kosten' => [
            'label' => 'Gesamt-VO ',
            'type' => 'number',
            'suffix' => ' €',
            "decimals" => 2,
            "decPoint" => ",",
            "thousandSep" => ".",
        ],
        'Erreichte Ziele' => [
            'label' => 'Abzug Ziele (bereinigt)',
            'type' => 'number',
            'suffix' => ' €',
            "decimals" => 2,
            "decPoint" => ",",
            "thousandSep" => ".",

        ],
        'Alle Ziele erreicht' => [
            'label' => 'Max. möglicher Abzug (bereinigt)',
            'type' => 'number',
            'suffix' => ' €',
            "decimals" => 2,
            "decPoint" => ",",
            "thousandSep" => ".",
        ],
    ],
    'stacked' => true,
    'colorScheme' => ['#475C71', '#714771', '#EE614F']
]);

Sebastian Morales commented on May 4, 2021

Peter, pls try to arrange your $data array column indexes in the same order. Specifically, from this:

$data =
    [
        [
            'category' => 'Verordnungskosten',
            'Erreichte Ziele' => $this->dataStore('ZqData1')->sum('erf_bereinigung'),
            'Alle Ziele erreicht' => $this->dataStore('ZqData1')->sum('opt_bereinigung'),
            'VO-Kosten' => $this->dataStore('PvbDwv')->sum('vk') - $this->dataStore('ZqData1')->sum('erf_bereinigung') - $this->dataStore('ZqData1')->sum('opt_bereinigung'),

        ],
        [
            'category' => 'Durchschnittswertevolumen',
            'VO-Kosten' => $this->dataStore('PvbDwv')->sum('dwv'),
            'Erreichte Ziele' => 0,
            'Alle Ziele erreicht' => 0,

        ],

    ];

to this:

$data =
    [
        [
            'category' => 'Verordnungskosten',
            'Erreichte Ziele' => $this->dataStore('ZqData1')->sum('erf_bereinigung'),
            'Alle Ziele erreicht' => $this->dataStore('ZqData1')->sum('opt_bereinigung'),
            'VO-Kosten' => $this->dataStore('PvbDwv')->sum('vk') - $this->dataStore('ZqData1')->sum('erf_bereinigung') - $this->dataStore('ZqData1')->sum('opt_bereinigung'),

        ],
        [
            'category' => 'Durchschnittswertevolumen',
            'Erreichte Ziele' => 0,
            'Alle Ziele erreicht' => 0,
            'VO-Kosten' => $this->dataStore('PvbDwv')->sum('dwv'),

        ],

    ];

Pls keep this same order for all of your charts and check the charts' color order.

Peter Wendel commented on May 18, 2021

Hello! Sorry for the alte answer!

That seems to solve the problem. Thanks for your help!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

ChartJS