Alpha Video Training
Results 1 to 10 of 10

Thread: Pie chart using calculated fields

  1. #1
    Member preston2's Avatar
    Real Name
    Preston
    Join Date
    Nov 2011
    Posts
    764

    Default Pie chart using calculated fields

    I am trying to setup a pie chart on a form that needs to draw the data from 3 calculated fields.

    I would just use the built-in documentation to try and figure this out but Alpha has disabled all image examples so it is hard to tell if you are reading the right part of the docs for things like this.

    Calculated fields I need to pull from are:

    CALC->Sales_tot

    CALC->Comish_Tot

    CALC->Paid_Tot

    Will keep looking for the answer myself but if anyone has a clue, thanks in advance.

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Pie chart using calculated fields

    These are form level or table level? The AlphaSports sample uses a table level calc field in one of the graphs on the ProductSalesByState form. Not sure about using form level calculations. They do use a mapped table as well.
    There can be only one.

  3. #3
    Member preston2's Avatar
    Real Name
    Preston
    Join Date
    Nov 2011
    Posts
    764

    Default Re: Pie chart using calculated fields

    Quote Originally Posted by Stan Mathews View Post
    These are form level or table level? The AlphaSports sample uses a table level calc field in one of the graphs on the ProductSalesByState form. Not sure about using form level calculations. They do use a mapped table as well.
    Form level.

    I guess I could add 3 more fields to the parent table and then have an event on the form that forces the forms calculated fields to get writen to the table.

    Just did not want to go through all of that if I could get out of it.

  4. #4
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,713

    Default Re: Pie chart using calculated fields

    see new wiki help

    Hi Preston,
    According to that little bit of info, a chart embedded on a form can use the form variables. So create your 3 calcs and 3 vars and set the vars to the calcs in an OnFetch or button event.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

  5. #5
    Member preston2's Avatar
    Real Name
    Preston
    Join Date
    Nov 2011
    Posts
    764

    Default Re: Pie chart using calculated fields

    Robin, you must see more there then I do.

    I am going to watch some of the videos but so far the docs and "New Wiki" are not much help.

    I mean you can make a chart in Excel or Quatro Pro in just a few seconds but the Alpha chart supercontrol is being a pain in the rear. I do not see why showing 3 values on a chart in Alpha is so screwy. I can get it to show a chart that is not really a chart, but two separate circles, and they are just grey.

    Right now I am just going to move on as the chart is not a necessity but would have been a nice addition to the form.

  6. #6
    Member preston2's Avatar
    Real Name
    Preston
    Join Date
    Nov 2011
    Posts
    764

    Default Re: Pie chart using calculated fields

    I have come to the conclusion that Alpha cannot do charts the way I need them to work.

    At least I have not found a way. Alpha insist on using ONE field (column), variable or calculated field as a series even if you have set it to use multiple fields. If you select multiple fields it then wants to build a series for each field.

    I need it to look at 3 different fields(columns, all on the same row) or 3 different variables or 3 different calculated fields on a form.

    I can put 3 different values in 3 different cells in Excel and wa-la, an f'ing chart but when it comes to Alpha's embedded chart, forget it.

  7. #7
    Member preston2's Avatar
    Real Name
    Preston
    Join Date
    Nov 2011
    Posts
    764

    Default Re: Pie chart using calculated fields

    Looks like I should be able to create a chart or charts the way I want using Google Charts for Developers.

    This is a rough of one I created with just a few minutes of coding. It is displayed on a Desktop Form in my app.


    It does require that the computer is connected to the internet so it can access the Google Forms api but the file with the code and data is stored on the local machine.

    Right now I am using static code but as soon as I figure out the best way to generate and write the html to a local file substituting static values for those in variables, I will post my code for others to play with.

    It also looks like I may be able to use a ui_dlg_box() to display the chart on the fly. I will investigate this as well.

    Here is the rough code so far to generate the chart. When I get more into it I will have it substitue the values in variables for the static ones under data.addrows([

    Code:
    <html>
      <head>
        <!--Load the AJAX API-->
        <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
        <script type="text/javascript">
    
          // Load the Visualization API and the corechart package.
          google.charts.load('current', {'packages':['corechart']});
    
          // Set a callback to run when the Google Visualization API is loaded.
          google.charts.setOnLoadCallback(drawChart);
    
          // Callback that creates and populates a data table,
          // instantiates the pie chart, passes in the data and
          // draws it.
          function drawChart() {
    
            // Create the data table.
            var data = new google.visualization.DataTable();
            data.addColumn('string', 'Sales');
            data.addColumn('number', 'Commission');
            data.addRows([
              ['Sales', 2220.35],
              ['Commission', 200.59],
              ['Paid', 175.59],
              ['Due', 25.00]
            ]);
    
            // Set chart options
            var options = {'title':'Sales Performace',
                           'width':400,
                           'height':300};
    
            // Instantiate and draw our chart, passing in some options.
    		var formatter = new google.visualization.NumberFormat(
        {prefix: '$', negativeColor: 'red', negativeParens: true});
    formatter.format(data, 1); // Apply formatter to second column
    
            var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
            chart.draw(data, options);
          }
        </script>
      </head>
    
      <body>
        <!--Div that will hold the pie chart-->
        <div id="chart_div"></div>
      </body>
    </html>

  8. #8
    Member preston2's Avatar
    Real Name
    Preston
    Join Date
    Nov 2011
    Posts
    764

    Default Re: Pie chart using calculated fields

    Ok, I have gotten the code working to write and rewrite the local html file as data changes. This works perfectly for now.

    I am displaying the html that contains the chart on a form using the supercontrol "Web Content".

    I am now trying to figure out how to make the "Web Content" refresh every time I change records. The underlying html changes but the "Web Content" does not update.

    I have tried <object>.refresh() and even re-syncing the display but nothing works yet. I have looked at the "Web Content" object properties in the object explorer but there is no help on what some of the setting may or may not do.

    Anyone have a clue? Or maybe another way to display an html file on a form so it can be refreshed/updated with changes to the record on when going to a different record?

    Just for anyone that wants to know, here is the code that writes and updates the file. I currently have it in the forms OnFetch event.

    Code:
    dim vn_sales as n
    dim vn_comish as n
    dim vn_paid as n
    dim vn_due as n
    
    
    vn_due = topparent:Comish_due.value
    vn_sales = topparent:Sales_tot_sp.value
    vn_comish = topparent:Comish_tot_sp.value
    vn_paid = topparent:Paid_tot_sp.value
    
    dim vc_html as c
    vc_html = "<html>"+crlf()
    vc_html=vc_html+"<head>"+crlf()
    vc_html=vc_html+"<!--Load the AJAX API-->"+crlf()
    vc_html=vc_html+"<script type=""text/javascript"" src=""https://www.gstatic.com/charts/loader.js""></script>"+crlf()
    vc_html=vc_html+"<script type=""text/javascript"">"+crlf(2)
    vc_html=vc_html+"// Load the Visualization API and the corechart package."+crlf()
    vc_html=vc_html+"google.charts.load('current', {'packages':['corechart']});"+crlf(2)
    vc_html=vc_html+"// Set a callback to run when the Google Visualization API is loaded."+crlf()
    vc_html=vc_html+"google.charts.setOnLoadCallback(drawChart);"+crlf(2)
    vc_html=vc_html+"// Callback that creates and populates a data table,"+crlf()
    vc_html=vc_html+"// instantiates the pie chart, passes in the data and"+crlf()
    vc_html=vc_html+"// draws it."+crlf()
    vc_html=vc_html+"function drawChart() {"+crlf(2)
    vc_html=vc_html+"// Create the data table."+crlf()
    vc_html=vc_html+"var data = new google.visualization.DataTable();"+crlf()
    vc_html=vc_html+"data.addColumn('string', 'Sales');"+crlf()
    vc_html=vc_html+"data.addColumn('number', 'Commission');"+crlf()
    vc_html=vc_html+"data.addRows(["+crlf()
    vc_html=vc_html+"['Sales', "+vn_sales+"],"+crlf()
    vc_html=vc_html+"['Commission', "+vn_comish+"],"+crlf()
    vc_html=vc_html+"['Paid', "+vn_paid+"],"+crlf()
    vc_html=vc_html+"['Due', "+vn_due+"]"+crlf()
    vc_html=vc_html+"]);"+crlf(2)
    vc_html=vc_html+"// Set chart options"+crlf()
    vc_html=vc_html+"var options = {'title':'Sales Performace',"+crlf()
    vc_html=vc_html+"'width':400,"+crlf()
    vc_html=vc_html+"'height':300};"+crlf(2)
    vc_html=vc_html+"// Instantiate and draw our chart, passing in some options."+crlf()
    vc_html=vc_html+"var formatter = new google.visualization.NumberFormat("+crlf()
    vc_html=vc_html+"{prefix: '$', negativeColor: 'red', negativeParens: true});"+crlf()
    vc_html=vc_html+"formatter.format(data, 1); // Apply formatter to second column"+crlf(2)
    vc_html=vc_html+"var chart = new google.visualization.PieChart(document.getElementById('chart_div'));"+crlf()
    vc_html=vc_html+"chart.draw(data, options);"+crlf()
    vc_html=vc_html+"}"+crlf()
    vc_html=vc_html+"</script>"+crlf()
    vc_html=vc_html+"</head>"+crlf(2)
    vc_html=vc_html+"<body>"+crlf()
    vc_html=vc_html+"<!--Div that will hold the pie chart-->"+crlf()
    vc_html=vc_html+"<div id=""chart_div""></div>"+crlf()
    vc_html=vc_html+"</body>"+crlf()
    vc_html=vc_html+"</html>"
    
    file_pointer = file.create("C:\T-Six\Charts\test1.html",FILE_RW_SHARED)
    file_pointer.write(vc_html)
    file_pointer.flush()
    file_pointer.close()
    
    WebContent1.refresh()
    Parentform.resynch()

  9. #9
    Member
    Real Name
    ujwalsaurav
    Join Date
    Dec 2019
    Posts
    8

    Default Re: Pie chart using calculated fields

    Can I just get the google charts data from xbasic function and use them in javascript functions.

  10. #10
    "Certified" Alphaholic Ted Giles's Avatar
    Real Name
    Ted Giles
    Join Date
    Aug 2000
    Location
    In the Wolds, Louth, Lincolnshire, UK
    Posts
    4,446

    Default Re: Pie chart using calculated fields

    Well that went well!
    Ted Giles
    Example Consulting - UK
    .

    http://ec12.example-software.com//
    See our site for Alpha Support, Conversion and Upgrade.

Similar Threads

  1. Report with subreport and embedded chart --> chart results depends on placement
    By Rida Alhasan in forum Alpha Five Version 11 - Desktop Applications
    Replies: 10
    Last Post: 01-01-2014, 04:47 AM
  2. Replies: 0
    Last Post: 07-03-2009, 05:25 AM
  3. Sample Chart in Report - Just as Chart in Form
    By Robert Rough in forum Archived Wishlist
    Replies: 0
    Last Post: 10-05-2007, 04:35 AM
  4. Max value for fields in a row (query, calculated fields)
    By johnf in forum Web Application Server v7
    Replies: 1
    Last Post: 01-24-2007, 05:38 AM
  5. Calculated Fields vs. Calculated Field Rule
    By Rhett Scott in forum Alpha Five Version 4
    Replies: 12
    Last Post: 07-07-2002, 05:58 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •