Format Value Chart PrimeFaces - Donut

Post Reply
User avatar
Jarciano
Posts: 27
Joined: 16 Feb 2016, 13:41
Location: Brasil
Contact:

25 May 2018, 15:07

Hello,

I'm having trouble formatting the values inside the Donut chart, see from the photo that the other models the code I added in javascript made the perfect formatting, but I can not do the same for the Donut chart.

https://imgsafe.org/image/80a57c7d2f

Javascript code:

Code: Select all

function skinDonut() {
                this.cfg.shadow = false;
                this.cfg.title = '';
                this.cfg.seriesColors = ['#3984B8', '#39B8B6', '#7E8DCD', '#F5A213', '#DC6061'];
                this.cfg.grid = {
                    background: '#ffffff',
                    borderColor: '#ffffff',
                    gridLineColor: '#dce2e7',
                    shadow: false
                };
                this.cfg.axesDefaults = {
                    rendererOptions: {
                        textColor: '#757575',
                    }
                };
                this.cfg.seriesDefaults = {
                    renderer: $.jqplot.DonutRenderer,
                    shadow: false,
                    lineWidth: 1,
                    markerOptions: {
                        shadow: false,
                        size: 7,
                        style: 'circle'
                    }
                }
            }
            //Format value chart PrimeFaces.
            $.jqplot.sprintf.thousandsSeparator = '.';
            $.jqplot.sprintf.decimalMark = ',';
            
Java class:

Code: Select all

 private void LegendaGraficoInvestidoEstoque() {
        graficoInvestidoEstoque = criarGraficoInvestidoEstoque();
        graficoInvestidoEstoque.setExtender("skinDonut");
        //graficoInvestidoEstoque.setLegendPosition("w");
    }

    private DonutChartModel criarGraficoInvestidoEstoque() {
        DonutChartModel model = new DonutChartModel();

        Double realizado = getDao().valorInvestidoEstoque();
        Map<String, Number> circle1 = new LinkedHashMap<String, Number>();
        circle1.put("INVESTIDO R$", realizado);
        model.addCircle(circle1);
        return model;
    }
I hope you can help me!
--
Jarciano Silva
CEO - Chief Executive Officer
AJ Desenvolvimento | http://www.ajdesenvolvimento.com

User avatar
aragorn
Posts: 3081
Joined: 29 Jun 2013, 12:38

29 May 2018, 07:54

Could you please use setDatatipEditor method to format value?

Exp;

Code: Select all

//bean
donutModel1 = initDonutModel();
        donutModel1.setTitle("Donut Chart");
        donutModel1.setLegendPosition("w");
        donutModel1.setExtender("skinDonut");
        donutModel1.setDatatipEditor("donutDatatipEditor");
        
//JS
<script type="text/javascript">
    function skinDonut() {
        $.jqplot.sprintf.thousandsSeparator = '.';
        $.jqplot.sprintf.decimalMark = ',';
    }

    function donutDatatipEditor(str, seriesIndex, pointIndex, plot) {
        var strArr = str.split(' - '),
            parts = strArr[1].toString().split('.');

        var value_str = new String(parts[0]);
        for (var i=10; i>0; i--) {
            if (value_str == (value_str = value_str.replace(/^(\d+)(\d{3})/, "$1"+$.jqplot.sprintf.thousandsSeparator+"$2"))) break;
        }
        parts[0] = value_str;

        return strArr[0] + " - " + parts.join($.jqplot.sprintf.decimalMark);
    }
</script>


User avatar
Jarciano
Posts: 27
Joined: 16 Feb 2016, 13:41
Location: Brasil
Contact:

30 May 2018, 12:49

Hello,

Almost worked, see in the image how the formatting of the values was after adding your code.
Notice that he is rounding up the values, and he is not showing the (,).

https://imgsafe.org/image/e8181ca9bb

Correct: 253.032,54
Wrong: 253.033
--
Jarciano Silva
CEO - Chief Executive Officer
AJ Desenvolvimento | http://www.ajdesenvolvimento.com

User avatar
aragorn
Posts: 3081
Joined: 29 Jun 2013, 12:38

04 Jun 2018, 08:08

Thanks a lot for the update! I think you can change donutDatatipEditor method according to your issue. Please check the value of 'value_str' variable.

Best Regards,

User avatar
Jarciano
Posts: 27
Joined: 16 Feb 2016, 13:41
Location: Brasil
Contact:

04 Jun 2018, 15:05

Hello,
Sorry for not understanding, could be more specific how can I do this customization?
--
Jarciano Silva
CEO - Chief Executive Officer
AJ Desenvolvimento | http://www.ajdesenvolvimento.com

User avatar
aragorn
Posts: 3081
Joined: 29 Jun 2013, 12:38

11 Jun 2018, 08:52

Could you please check 'value_str' in the above code? Exp;

Code: Select all

function donutDatatipEditor(str, seriesIndex, pointIndex, plot) {
        var strArr = str.split(' - '),
            parts = strArr[1].toString().split('.');
	
	console.log("Value array: " + strArr);

        var value_str = new String(parts[0]);
        
        console.log("Before formating: " + value_str);
        
        for (var i=10; i>0; i--) {
            if (value_str == (value_str = value_str.replace(/^(\d+)(\d{3})/, "$1"+$.jqplot.sprintf.thousandsSeparator+"$2"))) break;
        }
        
        console.log("After formating: " + value_str);
        
        parts[0] = value_str;

        return strArr[0] + " - " + parts.join($.jqplot.sprintf.decimalMark);
    }

User avatar
Jarciano
Posts: 27
Joined: 16 Feb 2016, 13:41
Location: Brasil
Contact:

11 Jun 2018, 12:52

Hello,

Thanks a lot for the help, but from what I noticed by the logs and that the DonutChartModel method only brings integer value, it rounds out all the value that is passed to it, thus the log being brought.

Value array: PREVISTO R$,195667
Before formating: 195667
After formating: 195.667

Value array: PREVISTO R$,28000
Before formating: 28000
After formating: 28.000

Value array: REALIZADO R$,50000
Before formating: 50000
After formating: 50.000
--
Jarciano Silva
CEO - Chief Executive Officer
AJ Desenvolvimento | http://www.ajdesenvolvimento.com

User avatar
aragorn
Posts: 3081
Joined: 29 Jun 2013, 12:38

13 Jun 2018, 08:02

Thanks a lot for the update! Maybe, you can use setDataFormat method to format model value.

Post Reply

Return to “Paradise - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest