Amcharts - radar chart for one and two data items (amcharts4)

Viewed 230

I am trying to display hexagon or octagon shape like radar series axis in case when I have only one or two items in data. Right Now it renders like that.

enter image description here

Following is my code snippet. I have looked at adapters for radar chart. So far, nothing useful found. https://www.amcharts.com/docs/v4/reference/radarchart/#Adapters

Upon debugging, I found that series.pixelHeight is 0. Can you guys give some pointers. or show me the way?

    const chart = am4core.create('al-radial-chart', am4charts.RadarChart)

    chart.logo.disabled = true
    chart.data = data
    chart.radius = am4core.percent(70)

    //* Create axes */
    const categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis())
    const valueAxis = chart.yAxes.push(new am4charts.ValueAxis())

    // Fields
    categoryAxis.dataFields.category = 'title'
    valueAxis.title.fontWeight = 'bold'
    valueAxis.renderer.gridType = 'polygons'

    // Labels
    valueAxis.renderer.labels.template.disabled = true
    categoryAxis.renderer.labels.template.fontSize = 12
    categoryAxis.renderer.labels.template.fill = am4core.color(colors.text)

    // Axes
    categoryAxis.renderer.grid.template.strokeWidth = 2
    categoryAxis.renderer.grid.template.strokeOpacity = 0.99
    categoryAxis.renderer.grid.template.fillOpacity = 0.05
    categoryAxis.renderer.labels.template.html = `
    <div style="width: ${
      window.innerWidth < 1000 ? 80 : window.innerWidth < 1500 ? 120 : 150
    }px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: center;">{category}</div>
    <div style="text-align: center; font-weight: bold">{score.formatNumber("#,###.0")}</div>`
    categoryAxis.renderer.labels.template.tooltipText = `[bold]{title}[/]\n score is [bold]{score.formatNumber("#,###.0")}[/]`
    categoryAxis.tooltip.getFillFromObject = false
    categoryAxis.tooltip.background.fill = am4core.color(colors.turq)
    categoryAxis.tooltip.background.stroke = am4core.color(colors.turq)

    categoryAxis.renderer.grid.template.fill = am4core.color(colors.gridFill)
    categoryAxis.renderer.grid.template.stroke = am4core.color(colors.lines)

    valueAxis.renderer.grid.template.strokeWidth = 2
    valueAxis.renderer.grid.template.strokeOpacity = 0.99
    valueAxis.renderer.grid.template.fillOpacity = 0.05
    valueAxis.renderer.grid.template.fill = am4core.color(colors.gridFill)
    valueAxis.renderer.grid.template.stroke = am4core.color(colors.lines)

    valueAxis.zIndex = 1
    categoryAxis.zIndex = 2

    /* Create and configure series */
    const series = chart.series.push(new am4charts.RadarSeries())
    // series.zIndex = 1
    series.dataFields.valueY = 'score'
    series.dataFields.categoryX = 'title'
    series.strokeWidth = 2
    series.stroke = am4core.color(colors.turq)
    series.fillOpacity = 0.4
    series.sequencedInterpolation = true
    series.sequencedInterpolationDelay = 100
1 Answers

I have created dummy data with valueAxis values set to zero and with different titles. Have used the categoryAxis htmlOutput adapter to hide those labels. Because my values were zero chart rendered correctly. Will post a code solution to this problem shortly.

Related