2017-05-02 3 views
1

Ich habe eine Anforderung, wo ich eine vollständig angepasste Y-Achse benötigen. Ich möchte die Uhr 'Stunden' auf der Y-Achse eines Balkendiagramms anzeigen.Balkendiagramme - Y-Achse anpassen

Aber die Anforderung ist, dass meine Y-Achse sollte beginnen -> 19,20,21,22,23,24,01,02,03,04,05,06,07,08,09,10, 11,12,13,14,15,16,17,18

So soll meine Y-Achse aussehen.

Ich habe versucht, mit der Option "Bereich: [a-b]", aber es sortiert die Nummern automatisch in aufsteigender Reihenfolge.

PS: Ich verwende plotly, aber wenn es ein anderes Diagramm-Framework gibt, das den Zweck erfüllen kann, werde ich mich dafür entscheiden.

var trace1 = { 
      x: ['JP','CN','TW','AU','HK','MY','PH','SG','SP','BN','LK','MO','TH','VB','VN','ID','BD','IN','NP','PK','AE','AO','DF','IQ','MU','BH','OM','ZA','ZM','KE','ZW','BW','TZ','UG','JO','QA','GB','CI','CM','GH','GM','NG','SL','US','BR'], 
      y: ['19.00','20.30','20.30','21.00','21.00','21.00','21.00','21.00','21.00','22.00','22.00','22.00','22.00','22.00','22.00','22.15','22.30','22.30','22.30','23.00','23.30','23.30','23.30','23.30','23.30','24.00','24.00','24.30','24.30','24.35','24.35','24.40','24.45','24.50','01.00','01.00','03.30','04.30','04.30','04.30','04.30','04.30','04.30','05.30','07.30'], 
      mode: 'markers', 
      marker: { 
        color: 'rgb(128, 0, 128)', 
        size: 8 
      }, 
      line: { 
        color: 'rgb(128, 0, 128)', 
        width: 1 
      } 
     }; 

     var trace2 = { 
      x: ['JP','CN','TW','AU','HK','MY','PH','SG','SP','BN','LK','MO','TH','VB','VN','ID','BD','IN','NP','PK','AE','AO','DF','IQ','MU','BH','OM','ZA','ZM','KE','ZW','BW','TZ','UG','JO','QA','GB','CI','CM','GH','GM','NG','SL','US','BR'] , 
      y: ['22.03','1.13','1.24','24.47','3.29','4.57','23.24','2.17','1.06','24.39','3.01','24.53','3.10','24.49','24.59','1.16','2.29','3.03','1.27','1.23','3.07','7.18','2.54','2.33','3.22','3.03','1.48','5.40','5.40','5.40','6.07','5.40','5.40','5.40','6.46','2.27','6.46','6.19','6.19','8.31','8.56','6.50','6.19','13.59','9.23'], 
        mode: 'markers', 
        marker: { 
        color:'rgb(0, 255, 0)', 
        size : 6 
        } 
       }; 


       var data = [trace1,trace2]; 

       var layout = { 
       autosize: false, 
       width: 1400, 
       height: 700, 
        title: 'Magellan Batch DashBoard', 
        font:{ 
        family: 'Raleway, snas-serif' 
        }, 
        showlegend: false, 
        xaxis: { 
        title: 'Countries', 
        tickangle: -45, 
        }, 
        yaxis: { 
         autotick: false, 
         ticks: 'outside', 
         tick0: 0, 
         dtick: 1, 
         ticklen: 8, 
         tickwidth: 4, 
        range : [19,20,21,22,23,24,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18], 
        title : 'Time of execution for each country', 
        zeroline: false, 
        }, 
        bargap :0.30 
       }; 

       Plotly.newPlot('myDiv', data, layout); 

Danke

+0

tatsächlich lesen

  • einstellen Welche Sprache verwenden Sie? Können Sie den Code hinzufügen, den Sie bisher versucht haben? –

  • +0

    Ich habe das obenstehende Code-Snippet in der Hauptfrage angehängt. Ich benutze Javascript. –

    +0

    Ich fürchte, dass dies in Plotly ziemlich schwierig ist. Sie müssten die Daten manipulieren und die Hoverinfo überschreiben. –

    Antwort

    1

    In Plotly Sie Folgendes tun könnte:

    • Ihre y-Werte im text Attribut setzen
    • Ihre y-Werte einstellen, das heißt 19 gleich 0 ist, 24 entspricht 5, usw.
    • Verwenden Sie tickvals, um einen Bereich von 0 bis 23 zu geben, aber verwenden Sie , um es '19' zuzu beschriften
    • gesetzt tickmode-array sicherstellen ticktext und tickvals sind die xaxisrange zu [-0.5, 23.5]

    var offset = 19; 
     
    var tick_str = ['19', '20', '21', '22', '23', '24', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18']; 
     
    
     
    var trace1 = { 
     
        x: ['JP', 'CN', 'TW', 'AU', 'HK', 'MY', 'PH', 'SG', 'SP', 'BN', 'LK', 'MO', 'TH', 'VB', 'VN', 'ID', 'BD', 'IN', 'NP', 'PK', 'AE', 'AO', 'DF', 'IQ', 'MU', 'BH', 'OM', 'ZA', 'ZM', 'KE', 'ZW', 'BW', 'TZ', 'UG', 'JO', 'QA', 'GB', 'CI', 'CM', 'GH', 'GM', 'NG', 'SL', 'US', 'BR'], 
     
        y: [], 
     
        text: ['19.00', '20.30', '20.30', '21.00', '21.00', '21.00', '21.00', '21.00', '21.00', '22.00', '22.00', '22.00', '22.00', '22.00', '22.00', '22.15', '22.30', '22.30', '22.30', '23.00', '23.30', '23.30', '23.30', '23.30', '23.30', '24.00', '24.00', '24.30', '24.30', '24.35', '24.35', '24.40', '24.45', '24.50', '01.00', '01.00', '03.30', '04.30', '04.30', '04.30', '04.30', '04.30', '04.30', '05.30', '07.30'], 
     
        mode: 'markers', 
     
        hoverinfo: 'text', 
     
        marker: { 
     
        color: 'rgb(128, 0, 128)', 
     
        size: 8 
     
        }, 
     
        line: { 
     
        color: 'rgb(128, 0, 128)', 
     
        width: 1 
     
        } 
     
    }; 
     
    
     
    var trace2 = { 
     
        x: ['JP', 'CN', 'TW', 'AU', 'HK', 'MY', 'PH', 'SG', 'SP', 'BN', 'LK', 'MO', 'TH', 'VB', 'VN', 'ID', 'BD', 'IN', 'NP', 'PK', 'AE', 'AO', 'DF', 'IQ', 'MU', 'BH', 'OM', 'ZA', 'ZM', 'KE', 'ZW', 'BW', 'TZ', 'UG', 'JO', 'QA', 'GB', 'CI', 'CM', 'GH', 'GM', 'NG', 'SL', 'US', 'BR'], 
     
        y: [], 
     
        text: ['22.03', '1.13', '1.24', '24.47', '3.29', '4.57', '23.24', '2.17', '1.06', '24.39', '3.01', '24.53', '3.10', '24.49', '24.59', '1.16', '2.29', '3.03', '1.27', '1.23', '3.07', '7.18', '2.54', '2.33', '3.22', '3.03', '1.48', '5.40', '5.40', '5.40', '6.07', '5.40', '5.40', '5.40', '6.46', '2.27', '6.46', '6.19', '6.19', '8.31', '8.56', '6.50', '6.19', '13.59', '9.23'], 
     
        mode: 'markers', 
     
        hoverinfo: 'text', 
     
        marker: { 
     
        color: 'rgb(0, 255, 0)', 
     
        size: 6 
     
        } 
     
    }; 
     
    
     
    var i = 0; 
     
    for (i = 0; i < trace1.text.length; i += 1) { 
     
        trace1.y.push((parseFloat(trace1.text[i]) - offset + 24) % 24); 
     
    } 
     
    for (i = 0; i < trace2.text.length; i += 1) { 
     
        trace2.y.push((parseFloat(trace2.text[i]) - offset + 24) % 24); 
     
    } 
     
    
     
    var ticks = [] 
     
    for (i = 0; i < tick_str.length; i += 1) { 
     
        ticks.push((parseInt(tick_str[i]) - offset + 24) % 24); 
     
    } 
     
    var layout = { 
     
        autosize: false, 
     
        width: 1400, 
     
        height: 700, 
     
        title: 'Magellan Batch DashBoard', 
     
        font: { 
     
        family: 'Raleway, snas-serif' 
     
        }, 
     
        showlegend: false, 
     
        xaxis: { 
     
        title: 'Countries', 
     
        tickangle: -45, 
     
        }, 
     
        yaxis: { 
     
        autotick: false, 
     
        ticks: 'outside', 
     
        tick0: 19, 
     
        dtick: 1, 
     
        ticklen: 8, 
     
        tickwidth: 4, 
     
        tickvals: ticks, 
     
        ticktext: tick_str, 
     
        tickmode: 'array', 
     
        title: 'Time of execution for each country', 
     
        zeroline: false, 
     
        range: [-0.5, 23.5] 
     
        }, 
     
        bargap: 0.30 
     
    }; 
     
    var data = [trace1, trace2]; 
     
    Plotly.newPlot('myDiv', data, layout);
    <script src="https://cdn.plot.ly/plotly-latest.min.js"></script> 
     
    <div id='myDiv'> </div>

    +0

    Es funktionierte :-) Sie sind ein Stern und ein Retter .. Vielen Dank von Kuala Lumpur .. –

    +0

    Irgendwelche Vorschläge für die folgende Frage. Vielen Dank im Voraus http://stackoverflow.com/questions/43751220/start-bar-from-a-particular-point-in-y-axis-instead-of-zero-in-plotly-bar-graph –

    +0

    gelöst :-) Danke Maximilian. Ich habe deinen Code gestern benutzt und es hat geholfen. –

    Verwandte Themen