KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.

Cube and chartjs options #1141

Open pargibay opened this topic on on Oct 31 - 9 comments

pargibay commented on Oct 31

Hi, How can i apply column settings in chartjs if i am using cube? I need to use the "spanGaps" property but I don't know how to do it. Thank you Regards

David Winterburn commented on Nov 4

Hi,

Which column setting did you want to use? For Chartjs, we have the columns property to set up columns to draw and their setting. Here's an example:

             LineChart::create(array(
                "title"=>"Stepped Line Chart",
                "dataSource"=>$time_sale,
                "columns"=>array(
                    "month",
                    "sale"=>array(
                        "label"=>"Sale",
                        "type"=>"number",
                        "prefix"=>"$",
                        "config"=>array(
                            "steppedLine"=>true,
                        )
                    ),
                ),
            )); 

Let us know if you want something else. Thanks!

pargibay commented on Nov 4

Hello david, Thanks for your answer. I know it this way (it's in the documentation) but I use the cube to get columns with non-fixed db names, so I can't define columns in this way, but I need to define properties for these columns Thanks Regards

pargibay commented 4 days ago

UP

KoolReport commented 4 days ago

Hi pargibay, you can get all columns name from dataStore, for example:

$columnNames = array_keys($this->dataStore("data-from-cube")->meta()["columns"]);

Now with all the name, you can construct a "columns" array:

$columns = array();
foreach($columnNames as $name)
{
    $columns[$name] = array(
        "label"=>ucfirst($name)
    );
}

Basically you can base on the name to add customized property for each columns and then later you can put into any widget of KoolReport:

LineChart::create(array(
    "dataSource"=>$this->dataStore("data-from-cube"),
    "columns"=>$columns
));

Hope that helps.

pargibay commented 2 days ago

Hi koolreport

Thank you, it is working but now the "config" => "spanGap" option is not recognized while, for example, "steppedLine" is working.

I print the column array

KoolReport commented 2 days ago

May I see your code?

pargibay commented 2 days ago

Hi, Of course:

$this->src("mssql")->query("SELECT m.code AS codigo,FORMAT(pk.prday,'yy-MM-dd') AS fecha,m.name AS producto,ROUND(pk.nominal, 2) AS kg_un,SUM(1) AS cantidad,ROUND(SUM(pk.nominal), 2) AS Kgs, ROUND(100 * AVG((pk.weight - pk.nominal)/ pk.nominal), 2) AS overweight FROM dbo.proc_packs AS pk INNER JOIN dbo.proc_materials AS m ON pk.material = m.material INNER JOIN dbo.proc_lots AS l ON pk.lot = l.lot WHERE (pk.prday BETWEEN CONVERT(datetime,:start,21) AND CONVERT(datetime,:end,21)) AND (pk.rtype <> 4) AND (m.code > '800000') AND m.name IN :products GROUP BY m.code, m.name, pk.prday, pk.nominal ORDER BY pk.prday")
->params(array(
            ":start"=>$this->params["dateRange"][0],
            ":end"=>$this->params["dateRange"][1],
            ":products"=>$this->params["products"],
        ))
->pipe(new Cube(array(
    "row"=>"fecha",
    "columns"=>"producto",
    "sum"=>"overweight",
)))
->pipe(new RemoveColumn(array(
      "{{all}}"
    )))
->pipe($this->dataStore('overweight'));

the view

$columnNames = array_keys($this->dataStore("overweight")->meta()["columns"]);
$columns = array();
foreach($columnNames as $name)
{
    $columns[$name] = array(
        "label"=>ucfirst($name),
        "suffix"=>"%",
        "config"=>array("spanGaps"=>false),
    );
}
$dataStore = $this->dataStore('overweight');
LineChart::create(array(
        "title"=>"Sobrepeso",
        "dataSource"=>$dataStore,
        "columns"=>$columns,
    ));
KoolReport commented 2 days ago

You do:

foreach($columnNames as $name)
{
    if($name!="fetcha")
        $columns[$name] = array("label"=>ucfirst($name));
    else    
        $columns[$name] = array(
            "label"=>ucfirst($name),
            "suffix"=>"%",
            "config"=>array("spanGaps"=>false),
        );
}

Let us know if it works.

pargibay commented 2 days ago

Hi,

It is not working, I got the same result.

maybe it is a bug?

KoolReport Is Free and Open-Source!

KoolReport is a professional php reporting framework which saves you tons of time to construct dynamic data report & dashboard.

  • Connect to various datasources such as MySQL, SQL Server, MongoDB or even from CSV or Excel file.
  • Contain series of powerful built-in data processes for your data manipulation.
  • Generate stunning charts and graphs to help you communicate data insights to your audiences effectively.
  • Integrate seamlessly with any php frameworks such as Laravel, CodeIgniter, Symfony.
Download Now and register our tutorials to get started!

Download KoolReport
help needed

ChartJS