ChartJS + drillDown

UI Components for JSF
Post Reply
fmezini
Posts: 1
Joined: 20 Mar 2019, 22:57

20 Mar 2019, 22:59

Hello people,

I'm trying to do a drill down in interactive ChartJS and everything works fine, but I need to add a button or link inside a canvas to back to previous graphic.

Is there any way to do this?

Thanks!

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

21 Mar 2019, 13:21

This is not a PF question but a ChartsJS question. I would say try and figure out how to do it with raw ChartsJS: https://www.chartjs.org/

Once you figure out how to do it with raw ChartsJS then using the "Extender" functionality of the PF Component will allow you to do the same thing.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

aryaDev
Posts: 3
Joined: 19 Apr 2019, 07:07

19 Apr 2019, 07:29

Hi Melloware,

I have a similar problem with the chartJS integration. I want to change the format of the y-axis in the bar chart component. In ChartJS this can be done by setting a callable function to the ticks element. But in the primefaces 7 version there is no possibility to set that callable function in the java code.

From your comment I understand, that I can get the functionality by setting the extender. Can you give me examples, how the function should be which is called by the extender? At the moment I get the function called, but don't know how to implement the function to change the y-axis labels.

Thank you in advance
Arya
Java developer


<jsf-version>2.2.19</jsf-version>
<primefaces-version>7.0</primefaces-version>

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

22 Apr 2019, 13:49

For examples using the extender see my solution here: https://stackoverflow.com/questions/557 ... primefaces

Here is an advanced example where I do exactly what you want and call a function to override the ticks.

Code: Select all

//This executes right before painting the line chart
function chartExtender() {
   var tickColor = "#666";
   var gridlineColor = "rgba(0,0,0,0.1)";
   
   if (!this.cfg.config.options) {
      this.cfg.config.options = {}
   }

   //copy the config options into a variable
   var options = $.extend(true, {}, this.cfg.config.options);

   options = {
      //remove the legend
      legend: {
         display: false
      },
      tooltips: {
         callbacks: {
            //add MW to label in tooltip
            label: function (tooltipItem, data) {
               return " " + tooltipItem.yLabel + " MW";
            }
         }
      },
      scales: {
         xAxes: [{
            display: true,
            type: "time",
            time: {
               parser: timeFormat,
               tooltipFormat: timeFormat,
               unit: 'hour',
               displayFormats: {
                  'hour': timeFormat
               }
            },
            gridLines: {
               color: gridlineColor
            },
            ticks: {
               fontColor: tickColor
            }
         }],
         yAxes: [{
            display: true,
            scaleLabel: {
               display: true,
               labelString: 'Capacity Available',
               fontSize: 13,
               fontColor: tickColor
            },
            ticks: {
               // add MW to y axis label
               callback: function (value, index, values) {
                  return value + " MW";
               },
               fontColor: tickColor
            },
            gridLines: {
               color: gridlineColor
            }
         }]
      }
   };

   //merge all options into the main chart options
   $.extend(true, this.cfg.config.options, options);
};
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 35 guests