Visualizzazione dei risultati da 1 a 2 su 2

Discussione: grafico in javascript

  1. #1

    grafico in javascript

    Ciao devo realizzare un grafico ed ho questo codice predo da un esempio di html
    il problema è il seguente il grafico è espresso in migliaia a me servirebbero numeri normali da 1 a 20
    come posso fare?
    Se ad esempio metto come
    v1=8
    v2=12

    lui mi considere 8 superiore a 12 e di condeguenza la barra di v1 è superiore di v2
    spero di essermi spiegata qualcuno può aiutarmi
    Grazie

    <% v1=5

    v2=8

    v3=9

    %>
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Hide JavaScript from Java-Impaired Browsers
    function getHplot(){
    n=new initArray(0,0,0,0,0,0)
    v=new initArray(0,0,0,0,0,0)
    rtitle=document.isnform.title.value;
    stitle=document.isnform.stitle.value;
    document.write('<TABLE BORDER=1 WIDTH=450><TR><TD '
    +'COLSPAN=3 ALIGN=CENTER>Grafico orizzontale a colonne</'
    +'B></TD></TR><TR><TD COLSPAN=3 ALIGN=CENTER>'
    +rtitle+'

    '+stitle+'</TD></TR>');
    v[0]=document.isnform.v1.value;
    v[1]=document.isnform.v2.value;
    v[2]=document.isnform.v3.value;
    v[3]=0;
    v[4]=0;
    v[5]=0;
    n[9]=0;
    n[6]=0;
    n[7]=0;
    for (var i=0;i<6;i++){
    if (v[i].length>n[9]){
    n[9]=v[i].length;
    }
    /* The next three lines are needed for visitors who
    still live on the Win3.x platform. If none of your
    visitors use older platforms,
    n[i]=eval(v[i]);
    may be substituted for these three lines. */
    str=v[i]
    StringToNumber();
    n[i]=num; // eval(v[i]); may be substituted
    if (n[i]<0){
    n[i]=0;
    }
    n[6]+=n[i];
    if (n[i]>n[2]){
    n[2]=n[i];
    }
    }
    n[10]=(n[9]+6)*8
    n[8]=n[2]/(450-n[10]); // my divisor
    document.write('<TR><TD>'+document.isnform.n1.value
    +'
    </TD><TD>[img]java98a.gif[/img]</TD><TD>'+v[0]+'</TD></TR>'
    +'<TR><TD>'+document.isnform.n2.value
    +'
    </TD><TD>[img]java98b.gif[/img]</TD><TD>'+v[1]+'</TD></TR>'
    +'<TR><TD>'+document.isnform.n3.value
    +'
    </TD><TD>[img]java98c.gif[/img]</TD><TD>'+v[2]+'</TD></TR>');
    document.write('<TR><TD COLSPAN=3><HR NOSHADE></TD></TR></TABLE>');
    getVplot();
    }

    function getVplot(){
    n[8]=n[7]/100;
    document.write('

    <TABLE BORDER=0 WIDTH=450><TR><TD'
    +' COLSPAN=6 ALIGN=CENTER>Grafico verticale a colonne</TD></TR>'
    +'<TR><TD COLSPAN=6 ALIGN=CENTER>'
    +rtitle+'

    '+stitle+'</TD></TR><TR>'
    +'<TD VALIGN=BOTTOM ALIGN=CENTER>[img]java98a.gif[/img]</TD>'
    +'<TD VALIGN=BOTTOM ALIGN=CENTER>[img]java98b.gif[/img]</TD>'
    +'<TD VALIGN=BOTTOM ALIGN=CENTER>[img]java98c.gif[/img]</TD>'
    +'<TD VALIGN=BOTTOM ALIGN=CENTER>[img]java98d.gif[/img]</TD>'
    +'<TD VALIGN=BOTTOM ALIGN=CENTER>[img]java98e.gif[/img]</TD>'
    +'<TD VALIGN=BOTTOM ALIGN=CENTER>[img]java98a.gif[/img]</TD></TR><TR>'
    +'<TD ALIGN=CENTER>'+document.isnform.n1.value+'</TD>'
    +'<TD ALIGN=CENTER>'+document.isnform.n2.value+'</TD>'
    +'<TD ALIGN=CENTER>'+document.isnform.n3.value+'</TD>'
    +'<TD ALIGN=CENTER>'+document.isnform.n4.value+'</TD>'
    +'<TD ALIGN=CENTER>'+document.isnform.n5.value+'</TD>'
    +'<TD ALIGN=CENTER>'+document.isnform.n6.value+'</TD></TR>'
    +'<TR><TD ALIGN=CENTER>'+v[0]+'
    </TD>'
    +'<TD ALIGN=CENTER>'+v[1]+'</TD>'
    +'<TD ALIGN=CENTER>'+v[2]+'</TD>'
    +'<TD ALIGN=CENTER>'+v[3]+'</TD>'
    +'<TD ALIGN=CENTER>'+v[4]+'</TD>'
    +'<TD ALIGN=CENTER>'+v[5]+'</TD></TR><TR><TD COLSPAN=6'
    +'><HR NOSHADE>

    </TD></TR></TABLE>');
    }
    var pwr=new initArray(1,2,3,4);
    pwr[0]=1;
    pwr[1]=2;
    pwr[2]=3;
    pwr[3]=4;
    pwr[4]=5;
    pwr[5]=6;
    pwr[6]=7;
    pwr[7]=8;

    /* Add more to array - pwr[8]=100000000, etc. -
    if strings longer than 8 are to be used. */
    var ns="012345678"
    var cr="";
    var str="";

    /* Pass this function a string (named "str") and it will
    return a number (named "num") Useful until all versions
    of JavaScript on all platforms support string to numeric
    conversions with predictability. */
    function StringToNumber(){
    num=0;
    strl=str.length;
    for (var j=strl-1;j>-1;j--){
    cr=str.substring(j,j+1);
    pos=ns.indexOf(cr);
    num+=pos*pwr[strl-j-1];
    }
    }

    function initArray() {
    this.length=initArray.arguments.length;
    for (var i=0;i<this.length;i++) {
    this[i]=initArray.arguments[i];
    }
    }
    // End Hiding -->
    </SCRIPT>


    </HEAD>

    <BODY bgcolor="white">

    <FORM NAME='isnform'>
    <TABLE BORDER=0 WIDTH=440>
    <TR><TD ALIGN=CENTER COLSPAN=10>Titolo del grafico: <INPUT TYPE='text' NAME='title' SIZE='35' VALUE='Grafico esemplificativo'>

    Caratteristiche: <INPUT TYPE='text' NAME='stitle' SIZE='40' VALUE='(valori in migliaia)'></TD></TR>
    <TR><TD>Anno:</TD>
    <TD><INPUT TYPE='text' NAME='n1' SIZE='3' VALUE='2002'></TD>
    <TD><INPUT TYPE='text' NAME='n2' SIZE='3' VALUE='2003'></TD>
    <TD><INPUT TYPE='text' NAME='n3' SIZE='3' VALUE='2004'></TD>
    <TD></TD>
    <TD></TD>
    <TD></TD></TR>
    <TR><TD>
    Valori:
    <TD><INPUT TYPE='text' NAME='v1' SIZE='5' VALUE="<% =v1%>"></TD>
    <TD><INPUT TYPE='text' NAME='v2' SIZE='5' VALUE="<% =v2%>"></TD>
    <TD><INPUT TYPE='text' NAME='v3' SIZE='5' VALUE="<%= v3%>"></TD>
    <TD></TD>
    <TD></TD>
    <TD></TD></TR>
    </TABLE>
    </FORM>
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Hide from JavaScript-Impaired Browsers
    getHplot();
    // End Hiding -->
    </SCRIPT>




    </body>
    </html>


  2. #2
    Frontend samurai L'avatar di fcaldera
    Registrato dal
    Feb 2003
    Messaggi
    12,924
    il codice che hai postato è un pò datato.

    Ti consiglierei vivamente di crearne uno ex-novo che faccia più uso di Css che di javascript e soprattutto che ti eviti l'uso delle tabelle.
    Vuoi aiutare la riforestazione responsabile?

    Iscriviti a Ecologi e inizia a rimuovere la tua impronta ecologica (30 alberi extra usando il referral)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.