Google图表绘制了不需要的值

时间:2016-07-27 11:24:33

标签: javascript charts google-visualization

我的网页上有一个Google图表,用于绘制用户输入的值(result1和result2) 我无法删除值Failed to list databases com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.1.26, port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.". at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:191) at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:242) at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2280) at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:493) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1387) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1068) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:904) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:451) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1014) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:233) at org.apache.sqoop.manager.SqlManager.makeConnection(SqlManager.java:883) at org.apache.sqoop.manager.GenericJdbcManager.getConnection(GenericJdbcManager.java:52) at org.apache.sqoop.manager.CatalogQueryManager.listDatabases(CatalogQueryManager.java:57) at org.apache.sqoop.tool.ListDatabasesTool.run(ListDatabasesTool.java:49) at org.apache.sqoop.Sqoop.run(Sqoop.java:143) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70) at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:179) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:218) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:227) at org.apache.sqoop.Sqoop.main(Sqoop.java:236) 16/07/27 16:35:24 ERROR sqoop.Sqoop: Got exception running Sqoop: java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.1.26, port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.". java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.1.26, port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.". at org.apache.sqoop.manager.CatalogQueryManager.listDatabases(CatalogQueryManager.java:73) at org.apache.sqoop.tool.ListDatabasesTool.run(ListDatabasesTool.java:49) at org.apache.sqoop.Sqoop.run(Sqoop.java:143) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70) at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:179) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:218) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:227) at org.apache.sqoop.Sqoop.main(Sqoop.java:236) Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.1.26, port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.". at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:191) at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:242) at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2280) at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:493) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1387) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1068) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:904) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:451) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1014) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:233) at org.apache.sqoop.manager.SqlManager.makeConnection(SqlManager.java:883) at org.apache.sqoop.manager.GenericJdbcManager.getConnection(GenericJdbcManager.java:52) at org.apache.sqoop.manager.CatalogQueryManager.listDatabases(CatalogQueryManager.java:57) ... 7 more 。如果我这样做,图表将无法渲染,但如果我将其保留,则x轴和y轴上的0点上有一个绘图点。
我需要图表来绘制[0,0]

[result1, result2]

1 个答案:

答案 0 :(得分:0)

有几个问题......

首先,正在使用值'result1''result2',而不是实际的变量值


['result1', 'result2']

应该是 [result1, result2]

接下来,输入字段值需要转换为数字 你可以使用parseFloat
parseFloat(document.getElementById('finalScore').value)

请记住,如果输入的数字不是数字,则可能会收到错误 使用isNaN验证号码

完成这些更改后,不需要[0, 0]

请参阅以下工作代码段...

google.charts.load('current', {
  callback: function () {
    "use strict";

    document.getElementById('drawFinalScore').addEventListener('click', drawChart, false);
    drawChart();

    function drawChart() {
      var result1 = parseFloat(document.getElementById('finalScore').value);
      if (isNaN(result1)) {
        result1 = 0;
      }
      var result2 = parseFloat(document.getElementById('finalScoreD').value);
      if (isNaN(result2)) {
        result1 = 0;
      }

      var data = google.visualization.arrayToDataTable([
        ['Quality', 'Delivery'],
        [result1, result2]
      ]);

      var options = {
        title: '',
        hAxis: {title: 'Quality', minValue: 0, maxValue: 1, gridlines: { count: 3, color: '#000000' }, titleTextStyle: {italic: false}},
        vAxis: {title: 'Delivery', minValue: 0, maxValue: 1, gridlines: { count: 3, color: '#000000'}, titleTextStyle: {italic: false}},
        width: 370,
        height: 300,
        colors: ['#6db33f'],
        pointSize: 30,
        pointShape: 'circle',
        fontName: 'proximaNovaLight',
        fontSize: '15',
        backgroundColor: { fill:'transparent' },
        legend: 'none',
      };

      var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
      chart.draw(data);
    }
  },
  packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<input id="finalScore" type="text" value="1" />
<input id="finalScoreD" type="text" value="1" />
<input id="drawFinalScore" type="button" value="Draw" />
<div id="chart_div"></div>