문제

나는 이것을 작동시킬 수없는 것 같다. 나는 차트에 하루에 총 주문 금액을 표시해야한다.

다음 코드로 작동 할 Open Flash 차트를 얻었습니다.


<?php

// Settings for Database Connection
include_once($root_folder_path . "includes/common.php");
include_once("./admin_common.php");
include_once("./ofc_chart_library/open-flash-chart.php");

$sql = "SELECT * from orders ORDER BY order_placed_date";
   if (!$sql) die('Invalid query: ' . mysql_error());

$result = mysql_query($sql);

$data = array();

while($row = mysql_fetch_array($result))
{
  $data[] = intval($row['order_total']);
}

/*
 *  Create a title object and set the text to present month.
 */
$title = new title( 'Monthly Sales Statistics for ' . date("F Y") . ' (US Dollar)' );
$title->set_style( "{font-size: 18px; font-family: Calibri; color: #808000; text-align: center;}" );

//Make our Bar Chart
$bar = new bar_filled('#f99bd6', '#ee0099');
$bar->set_values($data);

//Create a new Chart object
$chart = new open_flash_chart();

// add the title to the chart:
$chart->set_title( $title );
$chart->set_bg_colour("#FFFFFF");

// Display the bar object on the chart
$chart->add_element($bar);

/*
*  Create a Y Axis object
*/
$y_axis = new y_axis();
$y_axis->set_range(0, 12000, 1000);

// Add the y-axis object to the chart
$chart->add_y_axis($y_axis);

echo $chart->toPrettyString();
?>

이제 위의 코드가 잘 표시되었습니다. 스냅 샷이 있습니다.
http://static.zooomr.com/images/7749303_49fd833a44_o.jpg

내가 원하는 것은 x 축에 날짜를 표시하여 MySQL 데이터베이스에서 날짜 값을 가져 오는 것입니다.

다음은 날짜가 내 데이터베이스에 저장되는 방법입니다.

2008-12-30 00:06:24
2009-02-03 01:57:17
2009-02-03 01:58:27
2009-05-03 01:58:48
2009-06-03 02:00:31
2009-07-03 02:01:47
2009-07-03 02:02:31
2009-07-04 14:21:18
2009-07-04 14:21:36
2009-07-04 14:22:18
2009-07-04 14:23:29
2009-07-04 14:24:24

x 축에 날짜를 표시하기 위해 다음 코드를 시도했습니다.


<?php

include_once 'php-ofc-library/open-flash-chart.php';

//Connect to MySQL Database
$con = mysql_connect("localhost", "root", "password");
    if (!$con) die('Could not connect : ' . mysql_error());
$db_selected = mysql_select_db("cart",$con);
    if (!db_selected) die ("Could not find the database: " . mysql_error());

$sql = "SELECT * from orders ORDER BY order_placed_date";
    if (!$sql) die('Invalid query: ' . mysql_error());

$result = mysql_query($sql);

$amountData = array();


while($row = mysql_fetch_array($result))
{
  $amountData[] = intval($row['order_total']); 
}

$chart = new open_flash_chart();
$chart->set_title(new title('Open Flash Chart Downloads'));

//Make Bar Chart
$bar = new bar_filled('#df95c3', '#f34db7');
$bar->set_values($amountData);

//Create a new Chart object
$chart = new open_flash_chart();

/*
 *  Create a title object and set the text to present month.
 */
$title = new title( 'Monthly Sales Statistics for ' . date("F Y") . ' (US Dollar)' );
$title->set_style( "{font-size: 18px; font-family: Calibri; color: #808000; text-align: center;}" );

// add the title to the chart:
$chart->set_title( $title );
$chart->set_bg_colour("#FFFFFF");


// Add the bar object to the chart
$chart->add_element($bar);


//
// create an X Axis object
//
$x_axis = new x_axis();
// grid line and tick every 10
$x_axis->set_range(
    mktime(0, 0, 0, 1, 1, date('Y')),    // <-- min == 1st Jan, this year
    mktime(0, 0, 0, 1, 31, date('Y'))    // <-- max == 31st Jan, this year
    );
// show ticks and grid lines for every day:
$x_axis->set_steps(86400);

$labels = new x_axis_labels();
// tell the labels to render the number as a date:
$labels->text('#date:d#');
// generate labels for every day
$labels->set_steps(86400);
// only display every other label (every other day)
$labels->visible_steps(1);


// finally attach the label definition to the x axis
$x_axis->set_labels($labels);


$y_axis = new y_axis();
$y_axis->set_range(0, 3000, 200);

// Display the Axis on the Chart
$chart->set_x_axis($x_axis);
$chart->add_y_axis($y_axis);

echo $chart->toPrettyString();


?>

여기에 내가 얻은 것들이 다음과 같습니다.
http://static.zooomr.com/images/7749325_1c8b37fdf9_o.jpg

금액이 표시되지만 0 x 축에는 한 줄이 있습니다.

이 문제를 해결하려면 어떻게해야하므로 데이터베이스에서 주문 날짜를 가져온 다음 주문한 날짜에 따라 차트에 표시하십시오.

============================================================

아래는 순서 총계와 배치 날짜에 대한 JSON 데이터입니다.


<?php

include_once 'php-ofc-library/open-flash-chart.php';

//Connect to MySQL Database
$con = mysql_connect("localhost", "root", "password");
    if (!$con) die('Could not connect : ' . mysql_error());
$db_selected = mysql_select_db("cart",$con);
    if (!db_selected) die ("Could not find the database: " . mysql_error());

$sql = "SELECT * from orders ORDER BY order_placed_date";
    if (!$sql) die('Invalid query: ' . mysql_error());

$result = mysql_query($sql);

$dateData = array();
$TotalAmountData = array();

while($row = mysql_fetch_array($result))
{
  $TotalAmountData [] = intval($row['order_total']);
  $dateData[] = $row['order_placed_date'];

}

print '<pre>';
print_r( $TotalAmountData );
print_r( $dateData );
print '</pre>';[/code]

?>

이것은 다음 JSON 데이터를 보여줍니다.

Array  // This is the Total Order Amount Per Day
(
    [0] => 2499
    [1] => 199
    [2] => 449
    [3] => 299
    [4] => 359
    [5] => 279
    [6] => 1359
    [7] => 5099
    [8] => 2621
    [9] => 2169
    [10] => 2249
    [11] => 5509
)
Array // This is the DateTime on which the orders where placed
(
    [0] => 2008-12-30 00:06:24
    [1] => 2009-02-03 01:57:17
    [2] => 2009-02-03 01:58:27
    [3] => 2009-05-03 01:58:48
    [4] => 2009-06-03 02:00:31
    [5] => 2009-07-03 02:01:47
    [6] => 2009-07-03 02:02:31
    [7] => 2009-07-04 14:21:18
    [8] => 2009-07-04 14:21:36
    [9] => 2009-07-04 14:22:18
    [10] => 2009-07-04 14:23:29
    [11] => 2009-07-04 14:24:24
)

날짜부터 시간을 제거하여 날짜를 선택하려고했습니다.

SELECT DATE_FORMAT(order_placed_date, '%m-%d-%Y'), order_total FROM orders

그러나 위의 코드는 JSON 데이터에 대한 빈 값을 보여주었습니다.

업데이트 : 누구든지 도울 수 있습니까?

도움이 되었습니까?

해결책

당신의 가치는 실제로 하루에 총계입니까? 주문 날짜와 주문 당 총액 인 것 같습니다.

첫 번째 그래프의 문제점은 하루에 총계로 값을 조달하지 않는다는 것입니다. 열린 플래시 차트는이 작업을 수행하지 않습니다. SQL 쿼리의 일부로이 작업을 수행 할 수 있습니다 (예 : 사용 데이트() 날짜를 구문 분석하고 재구성하여 DateTimes를 날짜로 변환하거나 같은 날의 값을 함께 추가합니다. x 축 처리 방법에 따라 주문없이 며칠 동안 0 항목을 추가해야 할 수도 있습니다.

두 번째 그래프의 문제점은 초당 하나의 요소를 설정하지만 데이터는 하루에 이루어져야한다는 것입니다. 여기서 중요한 것은 이해하는 것입니다 라인 차트와 산란 차트의 차이점 오픈 플래시 차트에서. 라인 차트는 1 차원 데이터 포인트 배열을 사용하여 그려지는 반면 산란 차트는 코디네이트와 함께 표시됩니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top