質問

I am new to dojo chart. I am trying to create a stacked column chart using dojo . I am trying to show bar chart with line chart using dojo chart.Chart is appear. But here is my problem is how can i write my x-axis label name which comes from my database.I want to naming each bar's name on X-axis. My actual values comes from database. I searches from all stack overflow suggestion,dojo guides and from others but i could not found any proper solution.So i request to you please help me where my code is wrong.So here i can rectify me for futures.

Here is my code index.php

   <?php
    include "connection.php";
   $array = array();
   $array1 = array();
   $array2 =array();
     $query1 = "SELECT name,rate1,rate2 FROM TEST";
    $result = mysql_query($query1) or die ('Could not find Projects');
    while ($rows = mysql_fetch_array($result)){
    $array1[]=$rows['name'];
    $array1[]=$rows['rate1'];
    $array2[]=$rows['rate2'];
   }


   print_r($array1);
   print_r (json_encode($array1,JSON_NUMERIC_CHECK));
   print_r (json_encode($array2,JSON_NUMERIC_CHECK));
   <html><head>
  <link rel="stylesheet" href="dijit/themes/tundra/tundra.css">

   <script>dojoConfig = {parseOnLoad: true}</script>
<script src='dojo/dojo.js'></script>

  <script type="text/javascript">
  require(["dojox/charting/Chart",
 //"dojox/charting/plot2d/Lines", 
  "dojox/charting/axis2d/Default", 
  "dojox/charting/plot2d/StackedColumns", 
  "dojox/charting/action2d/Tooltip", 
    "dojo/ready", 
    "dojox/charting/widget/SelectableLegend"],
   function(Chart, Default, StackedColumns, Tooltip, ready, SelectableLegend) {
   ready(function() {

    var chart1 = new Chart("chart1");

    chart1.addPlot("stackedColumnsPlot", {
        type: StackedColumns,
        lines: true,
        areas: true,
        markers: true,
        tension: "S"
    });
    chart1.addPlot("linesPlot", {
        type: Lines,
        markers: true,
        stroke: {
            width: 2
        },
        tension: 2
    });

    chart1.addAxis("x");
    chart1.addAxis("y", {
        vertical: true
    });

    chart1.addSeries("Series 1", <?php echo json_encode($array1,JSON_NUMERIC_CHECK); ?>
        , {
        plot: "stackedColumnsPlot",
        stroke: {
            color: "blue"
        },
        fill: "lightblue"
    });
    chart1.addSeries("Series 2", <?php echo json_encode($array2,JSON_NUMERIC_CHECK); ?>, {
        plot: "stackedColumnsPlot",
        stroke: {
            color: "green"
        },
        fill: "lightgreen"
    });


    new Tooltip(chart1, "stackedColumnsPlot", {
        text: function(chartItem) {
            console.debug(chartItem);
            return "Value: " + chartItem.run.data[chartItem.index] + "; Stacked Value: " + chartItem.y;
        }
    });

    chart1.render();

    new SelectableLegend({
        chart: chart1,
        horizontal: false
    }, "chart1SelectableLegend");
        });
      });
        </script>

This is my code what i am writing for stacked column chart.So suggest me how can i write label name of x-axis in my chart which comes from my database.

役に立ちましたか?

解決

Add a label to the x axis:

Here are a few examples:

Use title property for one label for the entire axis.

chart.addAxis("x", {
   min: 0, max: 100,
   fontColor: "blue",
   vertical: true,
   fixLower: "major", fixUpper: "major",
   title: "X axis title",
   titleFont: "bold bold bold 12pt Arial,sans-serif",
   titleOrientation: "axis" 
});

For labels on each tick mark on the x axis:

var xAxisLabels = [{text: "Today",value: 1},{text: "-1",value: 2},{text: "-2",value: 3},{text: "-3",value: 4},{text: "-4",value: 5},{text: "-5",value: 6},{text: "-6",value: 7},{text: "WK-1",value: 8},{text: "WK-2",value: 9},{text: "WK-3",value: 10},{text: "WK-4",value: 11}];

chart.addAxis("x", {
 labels: xAxisLabels,
 fontColor: "blue",
     majorTicks:true,
 majorTickStep:1,
    minorTicks:false,
    max: 11
});

Not sure about the database part

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top