How do I apply Google column chart scroll?

Asked 2 years ago, Updated 2 years ago, 104 views

{%blockbarChart%}
<div id="columnchart_values" style="width:100%; height:300px;"></div>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
    google.charts.load("current", {packages:['corechart']});
    google.charts.setOnLoadCallback(drawChart);
    function drawChart() {
      var data = google.visualization.arrayToDataTable([
        ["Element", "Density", { role: "style" } ],
        ["Copper", 8.94, "#b87333"],
        ["Silver", 10.49, "silver"],
        ["Gold", 19.30, "gold"],
        ["Platinum", 21.45, "color: #e5e4e2"],
        ["Platinum", 21.45, "color: #e5e4e2"],
        ["Platinum", 21.45, "color: #e5e4e2"],
        ["Platinum", 21.45, "color: #e5e4e2"],
        ["Platinum", 21.45, "color: #e5e4e2"],
        ["Platinum", 21.45, "color: #e5e4e2"],
        ["Platinum", 21.45, "color: #e5e4e2"],
        ["Platinum", 21.45, "color: #e5e4e2"],
        ["Platinum", 21.45, "color: #e5e4e2"],
      ]);

      var view = new google.visualization.DataView(data);
      view.setColumns([0, 1,
                       { { calc: "stringify",
                         sourceColumn: 1,
                         type: "string",
                         role: "annotation" },
                       2]);

      var options = {
        // Chart Title
        title: "Chart Title Entry Interval",
        // Chart Title Style
        titleTextStyle:{
            color:'gray',
            fontSize:18,
            bold:true,
            //fontName:,
        },
        // Data Label Properties
        annotations: {
            textStyle: {
            //fontName: 'Times-Roman',
            fontSize: 18,
            bold: true,
            italic: false,
            color: 'blue',
            auraColor: 'blue',
            opacity: 0.8
            }
        },
        // Tooltip Properties
        tooltip: {textStyle: {color: '#FF0000', fontSize:17}, showColorCode: true},
        // Chart Background Color
        backgroundColor:{fill:'#f2f2f2', stroke:'skyblue', strokeWidth:4},
        chartArea:{width:'70%',height:'70%',backgroundColor:'yellow'},
        //
        explorer: { axis: 'horizontal', actions: ['dragToPan'] },



        width: 600,
        height: 300,
        bar: {groupWidth: "95%"},
        legend: { position: "none" },
      };
      var chart = new google.visualization.ColumnChart(document.getElementById("columnchart_values"));
      chart.draw(view, options);
  }

</script>
{% {% endblock %}

The code of the attached image. As you can see, as the x-axis increases, it narrows down so that you don't want to see it If the area is exceeded, can the horizontal scroll be applied?

google python javascript css

2022-09-20 20:01

1 Answers

Think of div#columnchart_values as one img and make it wide enough.

And make another div that wraps around div#columnchart_values and then give me this styling.

.chart-container {
    max-width: 600px; /* If you're using it in the bootstrap grid system, you can probably give it 100%
    overflow-x: scroll;
}

That'll do.

+ But maybe, good chart libraries offer Zoom control, so if you have Google visualization libraries, you'd better apply them. Please think that this problem that is facing me has already been experienced by a lot of people, and that there is already a solution, and that I have not yet explored it. It's usually like that.


2022-09-20 20:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.