0

Helloooo Guys, im stuck with something I have a single line chart that should pick data from specific column on database sum it and display it in chart

 <script>
           var ctx = document.getElementById('myChart').getContext('2d');
 var chart = new Chart(ctx, {
// The type of chart we want to create
type: 'line',

// The data for our dataset
data: {
    labels: ["January", "February", "March", "April", "May", "June", "July", "August", "Septembrie", "Octombrie", "Noiembrie", "Decembrie"],
    datasets: [{
        label: "Vanzare Lunara",
        backgroundColor: 'rgb(255, 99, 132)',
        borderColor: 'rgb(255, 99, 132)',
        data: [600, 800, 100, 16, 20, 21, 22, 23, 25, 26, 26],
    }]
},

// Configuration options go here
options: {}
});
</script>

This is the script that picks the data (600, 800, 100, etc)

the database name is highmob_comenzi it needs to pick data from 2 tables and colums and sum it table 1 - players , column totalvanzare

table 2 - vanzari , column totalvanzare

any ideea how to do it? :(

1 Answers1

1

Well first you need to make a database call obviously that will get the sum of whatever it is. Then you can do this:

$.ajax({
    url: 'url',
    type: 'POST', //Change this base on your requirement
    data: { 'data', 'some data if you need' },
    success: function (data) {
      var lineChartData = {
            labels: ["January", "February", "March", "April", "May", "June", "July", "August", "Septembrie", "Octombrie", "Noiembrie", "Decembrie"],
            datasets: [
                {
                    label: "Data set 1",
                    fillColor: "rgba(220,220,220,0.2)",
                    strokeColor: "rgb(23,127,255)",
                    pointColor: "rgb(23,127,255)",
                    pointStrokeColor: "#fff",
                    pointHighlightFill: "#fff",
                    pointHighlightStroke: "rgba(220,220,220,1)",
                    data: [data1, data2, data3]
                }
            ]

        }

        var options =
        {
            showTooltips: true,
            onAnimationComplete: function () { this.showTooltip(this.datasets[0].points, true); render(); },
            tooltipEvents: [],
            responsive: true,
            scaleFontColor: "#5BC236",
            scaleColor: "#000"
        }

        var ctx = document.getElementById("graph1").getContext("2d");
        var chart = new Chart(ctx).Line(lineChartData, options);
    }

function render() {
    var url = document.getElementById("graph1").toDataURL();
    document.getElementById("url1").src = url;
}

Hope this helps.

Zwei James
  • 73
  • 9
  • this one it really helps, the problem is that i dont know how to make a database call to get the sum of columns :( – Pirjol Nelu Dec 06 '17 at 08:57
  • Just search how to do it in java. It's pretty basic I think. This link might help you. https://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax Good luck! – Zwei James Dec 07 '17 at 02:09