Google 차트에서 데이터 색상을 다르게 지정하는 데 도움이 필요합니다. 두 개의 도메인을 날짜 및 순위 값과 비교하려고합니다.mySQL의 JSON 및 Google 차트의 색상 표시
'도메인'데이터를 생략하고 날짜 및 값 데이터 만 있으면 y 축의 날짜 데이터와 x 축의 값 데이터가있는 차트가 표시됩니다. 표에서 도메인 데이터를 사용하여 비교중인 데이터를 구분하고 싶습니다. 한 도메인의 도메인 하나와 다른 도메인의 도메인을 나타내는 막대 차트의 도메인을 구분할 수 있습니다.
나는 다음과 같은 오류가 아래 기본적으로 코드를 사용 :이 알려 대해가는 다른과 또는 더 쉬운 방법이 있다면 주어진 축에 모든 시리즈는 동일한 데이터 유형
이어야합니다.
테이블 구조 :
열 유형 널 (null) 기본 댓글
없음값 텍스트 없음
도메인 텍스트 여기 없음
내가 구글 친화적 인 JSON에 내 MySQL의 데이터를 변경하기 위해 무엇을 사용하지
날짜 텍스트 :
<?php
/* $server = the IP address or network name of the server
* $userName = the user to log into the database with
* $password = the database account password
* $databaseName = the name of the database to pull data from
*/
$host="127.0.0.1"; //replace with your hostname
$username="XXXXXXX"; //replace with your username
$password="XXX"; //replace with your password
$db_name="KYW_data"; //replace with your database
$con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name") or die ("cannot select DB");
mysql_select_db($db_name, $con);
// write your SQL query here (you may use parameters from $_GET or $_POST if you need them)
$query = mysql_query('SELECT date, value FROM KYW_Compete_rank');
$table = array();
$table['cols'] = array(
/* define your DataTable columns here
* each column gets its own array
* syntax of the arrays is:
* label => column label
* type => data type of column (string, number, date, datetime, boolean)
*/
array('label' => 'date', 'type' => 'string'),
array('label' => 'value', 'type' => 'number'),
array('label' => 'value', 'type' => 'string')
// etc...
);
$rows = array();
while($r = mysql_fetch_assoc($query)) {
$temp = array();
// each column needs to have data inserted via the $temp array
$temp[] = array('v' => $r['date']);
$temp[] = array('v' => $r['value']);
$temp[] = array('v' => $r['domain']);
// etc...
// insert the temp array into $rows
$rows[] = array('c' => $temp);
}
코드 aying 구글 차트 :
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "fetch.php",
dataType:"json",
async: false
}).responseText;
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);
// Instantiate and draw our chart, passing in some options.
new google.visualization.BarChart(document.getElementById('visualization')).
draw(data,
{title:"Rank Standings",
width:600, height:400,
vAxis: {title: "Year and Month"},
hAxis: {title: "Rank"}}
);
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="visualization"></div>
</body>
</html>
그렇지 않은 이유는 내가 조건을 설정하는 방법을 알고하지 않는 것이있을 수 있고 어쩌면 그건 작동 안함. 내 테이블에, 나는 도메인 열을 가지고 있으므로, 조건은 도메인 == 'utah.edu', 도메인 = 'utah.edu'또는 IF 문과 함께 다른 도메인을 잡을 다른 것과 같을까요? – Strj500
터미널을 다음과 같이 시도했습니다 :
mysql -u root -p -e '날짜 선택, SUM (IF (도메인 ='byu.edu ', 값, 0)) AS value_1, SUM (IF (도메인 ='유타 .edu ', value, 0)) AS value_2 FROM KYW_Compete_rank GROUP BY 날짜'KYW_data
및 1 줄에 '1054 (42S22) 오류가 있습니다. 알 수없는 열'byu.edu ''field list '에 " – Strj500
'byu.edu' 열을 선택하지 않았기 때문에 왜 그 오류가 발생하는지 알 수 있습니다. – asgallant