1

I am trying to use a pie chart from www.highcharts.com in justpy.

Page loads but the chart is not rendered.

I used code from this source: https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/pie-basic

I simplified code to narrow down a problem:

import justpy as jp

chart_options = """{
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        type: 'pie'
    },
    title: {
        text: 'Browser market shares in January, 2018'
    },
    tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    },
    accessibility: {
        point: {
            valueSuffix: '%'
        }
    },
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                format: '<b>{point.name}</b>: {point.percentage:.1f} %'
            }
        }
    },
    series: [{
        name: 'Brands',
        colorByPoint: true,
        data: [{
            name: 'Chrome',
            y: 61.41,
            sliced: true,
            selected: true
        }, {
            name: 'Internet Explorer',
            y: 11.84
        }, {
            name: 'Firefox',
            y: 10.85
        }, {
            name: 'Edge',
            y: 4.67
        }, {
            name: 'Safari',
            y: 4.18
        }, {
            name: 'Sogou Explorer',
            y: 1.64
        }, {
            name: 'Opera',
            y: 1.6
        }, {
            name: 'QQ',
            y: 1.2
        }, {
            name: 'Other',
            y: 2.61
        }]
    }]
}"""


def app():
    wp = jp.QuasarPage()
    h1 = jp.QDiv(a=wp, text="Testing Pie chart",
                 classes="text-h3 text-center q-py-xl q-px-xl")
    hc = jp.HighCharts(a=wp, options=chart_options)

    return wp

jp.justpy(app)

I tried to open it in different browsers. I tried to restart the server, ide. Most of the charts from highcharts.com are working(spline, areaspline, streamgraph). However, I encountered the same problem with the line chart: https://www.highcharts.com/docs/chart-and-series-types/line-chart.

Update. Adding working example for spline chart:

import justpy as jp

chart_options = """{
    chart: {
        type: 'spline',
        inverted: true
    },
    title: {
        text: 'Atmosphere Temperature by Altitude'
    },
    subtitle: {
        text: 'According to the Standard Atmosphere Model'
    },
    xAxis: {
        reversed: false,
        title: {
            enabled: true,
            text: 'Altitude'
        },
        labels: {
            format: '{value} km'
        },
        accessibility: {
            rangeDescription: 'Range: 0 to 80 km.'
        },
        maxPadding: 0.05,
        showLastLabel: true
    },
    yAxis: {
        title: {
            text: 'Temperature'
        },
        labels: {
            format: '{value}°'
        },
        accessibility: {
            rangeDescription: 'Range: -90°C to 20°C.'
        },
        lineWidth: 2
    },
    legend: {
        enabled: false
    },
    tooltip: {
        headerFormat: '<b>{series.name}</b><br/>',
        pointFormat: '{point.x} km: {point.y}°C'
    },
    plotOptions: {
        spline: {
            marker: {
                enable: false
            }
        }
    },
    series: [{
        name: 'Temperature',
        data: [[0, 15], [10, -50], [20, -56.5], [30, -46.5], [40, -22.1],
            [50, -2.5], [60, -27.7], [70, -55.7], [80, -76.5]]
    }]
}"""


def app():
    wp = jp.QuasarPage()
    h1 = jp.QDiv(a=wp, text="Testing Pie chart",
                 classes="text-h3 text-center q-py-xl q-px-xl")
    hc = jp.HighCharts(a=wp, options=chart_options)

    return wp


jp.justpy(app)
  • I saw question https://stackoverflow.com/questions/69391610/pie-chart-not-popping-up-highcharts but it is more complex as it reads data from CSV and that might be a different problem. – Oleksandr Yanov Dec 01 '21 at 08:18
  • Hi, a line chart and pie chart are the simplest examples of charts. Could you show example with spline, I try to have look at them. [Link demo](https://jsfiddle.net/BlackLabel/9u4jy0vL/) Meanwhile, check out this pie chart of the simplified version and let me know if it works. – Sebastian Hajdus Dec 02 '21 at 09:27
  • @SebastianHajdus Thank you for looking into this. Added working spline chart example. – Oleksandr Yanov Dec 03 '21 at 20:47

2 Answers2

0

What I found it's the first example that has loaded options for accessibility module. Have you joined this script to your scripts?

https://code.highcharts.com/modules/accessibility.js

Sebastian Hajdus
  • 1,422
  • 1
  • 5
  • 14
  • Thank you suggestion. No, I did not. My juspy lesson did not mention it. After you comment I tried to insert it via: ` wp.head_html = '\ \ \ '` But it did not work. – Oleksandr Yanov Dec 07 '21 at 06:18
  • Here is justpy tutorial. There should be information about adding script references to highcharts, but there is none, unfortunately. [link](https://justpy.io/charts_tutorial/creating_charts/) – Oleksandr Yanov Dec 07 '21 at 06:27
  • Here is the official tutorial from Highcharts, It can be useful if you are creating application. [Link](https://www.highcharts.com/blog/tutorials/python-angular-and-highcharts/), they used Python framework, database and Angular. – Sebastian Hajdus Dec 07 '21 at 09:22
  • Thank you for the link. They use Django + Angular and not using justpy. May be that's work, I don't know, I am interested in making hightcharts work through justpy. – Oleksandr Yanov Dec 10 '21 at 06:26
0

You will be able to get the pie chart to show by removing the following lines from your code:

plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,

So your script should read as follows:

import justpy as jp
chart_options = """{
chart: {
    type: 'pie'
},
title: {
    text: 'Browser market shares in January, 2018'
},
tooltip: {
    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
accessibility: {
    point: {
        valueSuffix: '%'
    }
},
plotOptions: {
    pie: {
        allowPointSelect: true,
        cursor: 'pointer',
        dataLabels: {
            enabled: true,
            format: '<b>{point.name}</b>: {point.percentage:.1f} %'
        }
    }
},
series: [{
    name: 'Brands',
    colorByPoint: true,
        data: [{
            name: 'Chrome',
            y: 61.41,
            sliced: true,
            selected: true
        }, {
            name: 'Internet Explorer',
            y: 11.84
        }, {
            name: 'Firefox',
            y: 10.85
        }, {
            name: 'Edge',
            y: 4.67
        }, {
            name: 'Safari',
            y: 4.18
        }, {
            name: 'Sogou Explorer',
            y: 1.64
        }, {
            name: 'Opera',
            y: 1.6
        }, {
            name: 'QQ',
            y: 1.2
        }, {
            name: 'Other',
            y: 2.61
        }]
    }]
}
"""


def app():
    wp = jp.QuasarPage()
    h1 = jp.QDiv(a=wp, text="Testing Pie chart", classes="text-h3 text-center q-py-xl q-px-xl")
    hc = jp.HighCharts(a=wp, options=chart_options)

return wp

jp.justpy(app)
sigarry
  • 1
  • 1