Syntax for adding Stacked Bar option to Pivot Chart?

I would like to create a chart with sales by category over time. The problem is that the number of categories increases over time, and I don’t want to maintain multiple series each time a new category is added. It seems a stacked bar pivot chart by date and category would be the best solution, but I can’t seem to figure out the syntax.

This is what I’m trying to accomplish, but grouping by multiple fields is not working:

var testChart = {
            id:"testChart",
            view:"pivot-chart",
            height:300,
            width:800,
            separateLabel: true,
            structure:{
                groupBy:["Category","Sale_Date"],
                values: [{name:"Sales", operation:"sum"}],
                filters:[{name:"Category",type:"select"}]
            },
            url:"data/reportDailySales.php"
};

In Pivot Chart, only one field can be used for data grouping.
But the Stacked Bar type can be added additionally. Please check the following sample: http://webix.com/snippet/b6549830

Unfortunately that doesn’t solve my problem. In that case, you know how many categories you have: just two (balance and oil). Is it possible to dynamically add to the values based on each category in my dataset?

In addition to initial values and configuring chart from UI (available for user), it is possible to set its configuration via define+render methods after init:

  $$("pivot").define("structure", {
    groupBy: "year",
    values: [{name:"balance", operation:"max"}]
  });
  $$("pivot").render();

In the next release, for the same purpose will be available setStructure method (already implemented in Pivot Table).

the number of categories increases over time

Here’s an example of implementation.
The only limitation so far is that the unused fields for stacked bar have to be defined as 0 in order to avoid any issue:
https://snippet.webix.com/oqulf0jy

We will consider the improvements for this behaviour.

Thank you Listopad for the ideas and the snippet. That makes sense that the 0 has to be defined. The issue I’m seeing though is that you are still writing the code to provide which values there are. What I’m looking for is something like this image:

Imgur

My source will be data from a MySQL database retrieved by a php script. I would love to just write a query that groups by year and category and returns the sales. I don’t want to update the Webix code each time we add a new category. It seems that currently this is the case though? (In this example above, ‘Carrots’ would have to be added as a values to the pivot chart once we start selling carrots.)