typpo / quickchart-java

Java client for quickchart.io chart API
10 stars 1 forks source link

Is there support for Quickchart's apexchart-server side rendering? #8

Open SalvatoreSA opened 1 week ago

SalvatoreSA commented 1 week ago

Quickchart's main docs specify it supports apexchart server-side rendering here. That is what we're mostly interested in, and we would like to use this repo to do that from our backend as we already use apexcharts in frontend and we'd rather not split the logic.

I haven't found anything mentioning apexcharts in this documentation or in the actual classes, am I right? If so, would it be doable implementing it? From what I see it's about modifying the url to include "/apex-charts/" in the beginning and using .setConfig to use an apexcharts config?

Thanks in advance!

SalvatoreSA commented 1 week ago

For now I worked around it without modifying this repo, but obviously it's pretty "ugly".

`import javax.annotation.PostConstruct;

import org.springframework.stereotype.Component;

import io.quickchart.QuickChart;

@Component public class ChartBuilder {

@PostConstruct
public void test() {
    this.buildChart();
}

public void buildChart() {
    QuickChart chart = new QuickChart("https", "quickchart.io/apex-charts", 443);

    String apexConfig = "{" +
            "  chart: {" +
            "    type: 'line'," +
            "    height: 350" +
            "  }," +
            "  series: [{" +
            "    name: 'Vendite'," +
            "    data: [10, 20, 15, 25, 35, 30]" +
            "  }]," +
            "  xaxis: {" +
            "    categories: ['Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu']" +
            "  }" +
            "}";

    chart.setConfig(apexConfig);
    String url = chart.getUrl().replace("/chart", "/render").replace("?w=500&h=300&devicePixelRatio=1.0&c", "?config");
    System.out.println(url);
}

}`

typpo commented 1 week ago

Hi @SalvatoreSA, you are correct, unfortunately you'll have to construct the URL yourself for the apex charts endpoint.

SalvatoreSA commented 1 week ago

Then I suppose you can close the ticket unless further information is available. Thanks!