Chartdirector - Linearmeter Chart Type

(15 posts) (2 voices)
  1. ajdjackson, Member

    Hi all

    Happy New Year.

    Is it possible to implement a Linearmeter chart type?

    I would like to display performance to goal and I think that the Linearmeter is the best type or do you have any suggestions on the best way to achieve similar?

    Chartdirector example can be found here -

    Thanks

    Jake

  2. myDBR Team, Key Master

    There are no LinearMeter charts at the moment, but you can create one by extending the echart-extension.

    --
    myDBR Team

  3. ajdjackson, Member

    Hi

    I've tried to creaate an extension but at the moment nothing displays. Can you give me a clue as to where I go next?

    Many thanks

    Jake

    class Ext_LinearMeter extends Ext_EChartC { protected function create() { $this->x = 250; $this->y = 75;

    $this->c = new LinearMeter($this->x, $this->y, silverColor(), 0, -2);

    $this->c->setMeter(15, 25, 220, 20, Top);

    $this->c->setScale(0, 100, 10);

    // Set 0 - 50 as green (99ff99) zone, 50 - 80 as yellow (ffff66) zone, and 80 - 100 as // red (ffcccc) zone $this->c->addZone(0, 50, 0x99ff99); $this->c->addZone(50, 80, 0xffff66); $this->c->addZone(80, 100, 0xffcccc);

    $this->c->addText(10, 68, "% to Target", "arialbd.ttf", 8, 0xc00000, BottomLeft);

    for ($i=0; $i < sizeof($this->dataIn); $i++) { $color = hexdec($this->options['dbr.echart.color']['color'.$i]);

    }

    $this->c->addTitle($this->options['dbr.echart']['name'], $this->title_font, $this->title_font_size, 0x000000);

    // Add a blue (0000cc) pointer at the specified value $this->c->addPointer($this->dataIn, 0x0000cc);

    } }

    I added this also:

    static function create_chart_and_print( $id, $options, $dataIn, $colInfo ) { $chart = null; switch ($options['dbr.echart']['type']) { case 'radar': case 'polar': $chart = new Ext_PolarChart(); break; case 'bubble': $chart = new Ext_BubbleChart(); break; case 'linearmeter': $chart = new Ext_LinearMeter(); break;

    I've added the following lines to my report:

    select 'dbr.echart', 'linearmeter', 'Test'; select 'dbr.echart.color', '0x80ff3333'; select 75;

  4. myDBR Team, Key Master

    Code looks ok to us. It should give you a chart.

    --
    myDBR Team

  5. ajdjackson, Member

    Hi

    I get nothing when the above is run - no errors - just blank page.

    The page source for the output contains:

    <div class="title">Test Select</div><object id="1" data="lib/mydbr_get_cd_chart.php?img=chart1&id=cho7tfuf94q3f7nbdcov4us1f754aaa0a759cd6&&stype=.svg" type="image/svg+xml" width="250" height="75" ></object></div>

    Cheers

    Jake

  6. ajdjackson, Member

    Hi

    I've had a further look at this issue.

    I tried to run one of the included chart extension type -

    select 'dbr.echart', 'radar', 'Example radar'; select 'dbr.echart.color', '0x80ff3333', '0x803333ff'; select 'dbr.echart.name', 'Model Saturn', 'Model Jupiter';

    select 80,70,70,60,50;

    Strangely I still get no output. Is there something missing in my setup? What should I check?

    Thanks

    Jake

  7. ajdjackson, Member

    Hi

    A bit of an update.

    I came across this post - Cannot create SVG chart

    So first I changed the Default Chart Format to PNG in Environment Settings. This resulted in 'placeholders' appearing where the chart should be.
    I then un-ticked 'Use embedded Charts' and the charts now appear. I then re-selected SVG but left 'Use embedded Charts' un-ticked. The charts appeared. So the issue is in embedded charts.

    Can you tell me what the implications of not using embedded charts are?

    Also my code does not pick up the date value of the pointer so my code must be wrong $this->c->addPointer($this->dataIn, 0x0000cc); Any idea what's wrong here?

    Cheers

    Jake

  8. myDBR Team, Key Master

    When you use embedded charts, the chart data is embedded into the HTML code. If you do not use embedded data, myDBR creates the charts in session and when page is loaded it fetched the data from the session.

    The benefit of the embedded charts is that myDBR can close the session sooner so long running reports will not block other reports from running.

    I overall, you will get best looking an performing charts if you use embedded SVG charts. With SVG charts the chart is drawn as vector object in client and can utilize native fonts instead of bitmaps.

    To debug the embedded charts, test if myDBR charts work in your setup when using embedded charts. Create a report with just one myDBR chart (an SVG pie chart for example). Then add '&getchart=1' to the URL. The result should be just the SVG code. Try this for both embedded and non-embedded charts.

    Also my code does not pick up the date value of the pointer so my code must be wrong $this->c->addPointer($this->dataIn, 0x0000cc); Any idea what's wrong here?

    $this->dataIn is a multidimensional array containing all possible result sets. To get the result from query "select 75;", get the first value of the first result set: $this->dataIn[0][0]

    --
    myDBR

  9. ajdjackson, Member

    Hi

    Thanks for getting back.

    $this->dataIn is a multidimensional array containing all possible result sets. To get the result from query "select 75;", get the first value of the first result set: $this->dataIn[0][0]

    Works great.

    When I test the charts this is what I find.

    myDBR's built-in reports all work when both SVG and embedded are selected.

    The issue of no chart displaying occurs when I use a chart that is defined in the echart extensiion ie the LinearMeter that I have added and also the RadarĀ¦Polar chart that existed (I haven't tried the Bubble Chart).

    To get around this is there a way to switch off embedding only when a echart is used?

    Cheers

    Jake

  10. myDBR Team, Key Master

    If your problem with embedded is just with the echarts, you can debug the code to see if $this->c->makeChart2 returns any data.

    We can add a Linearmeter chart to myDBR so you can use that as well.

    --
    myDBR Team

  11. ajdjackson, Member

    Hi

    $this->c->makeChart2

    Where do I insert this line?

    It would great if you could add this as a standard chart.

    I was hoping to pass the addText, $this->x, $this->y as well as the pointer value via the data query. The below seems to work.

    This is where I'm at:

    class Ext_LinearMeter extends Ext_EChartC { protected function create() { $this->x = $this->dataIn[0][1]; // meter size $this->y = $this->dataIn[0][2];

    $this->c = new LinearMeter($this->x, $this->y, silverColor(), 0, -2);

    $this->c->setMeter(15, 25, 220, 20, Top);

    $this->c->setScale(0, 100, 10);

    // Set 0 - 50 as green (99ff99) zone, 50 - 80 as yellow (ffff66) zone, and 80 - 100 as // red (ffcccc) zone $this->c->addZone(0, 50, 0x99ff99); $this->c->addZone(50, 80, 0xffff66); $this->c->addZone(80, 100, 0xffcccc);

    $this->c->addText(10, 68, $this->dataIn[0][0], "arialbd.ttf", 8, 0xc00000, BottomLeft);

    $this->c->addTitle($this->options['dbr.echart']['name'], $this->title_font, $this->title_font_size, 0x000000);

    // Add a blue (0000cc) pointer at the specified value $this->c->addPointer($this->dataIn[0][3], 0x0000cc);

    $textBoxObj = $this->c->addText(238, 70, $this->c->formatValue($this->dataIn[0][3], "2"), "arial.ttf", 8, 0xffffff, BottomRight); $textBoxObj->setBackground(0, 0, -1);

    } }

    I then use the following lines in the report:

    select 'dbr.echart', 'linearmeter', 'Unit Sales Performance';

    select "% to Target",250,75,75;

    I appreciate that I would still have to do a bit of work on the setMeter, setScale and $textBoxObj.

    Thanks for your help with this.

    Jake

  12. myDBR Team, Key Master

    $this->c->makeChart2

    Where do I insert this line?

    The echart extension has method print_chart() which, in case of embedded chart, uses $this->c->makeChart2() call to put out the chart data. The URL is generated with code:

    $url = 'data:image/'.image_data_uri_type($image_format).';base64,'.base64_encode($this->c->makeChart2($chart_director_format));

    Where the $chart_director_format is a constant (SVG in case of svg chart).

    --
    myDBR Team

  13. ajdjackson, Member

    Hi

    Strange one this.

    I re-ticked the use embedded charts option and my LinearMeter now is working whereas before nothing was displayed.

    The only thing I can think is that I had an error in my method. Do you think that the way I was addressing the addPointer data was incorrect and with no data being returned could result in no at all being displayed? However I received no error message in the code.

    It doesn't also explain why the Radar chart didn't display either if the embedded option is ticked. Very strange.

    Another strange thing is that the echart output must be cached somewhere.

    When I comment out the code to display the LinearMeter and just leave the code for the Radar echart chart I still get the LinearMeter displayed even after doing a forced refresh.

    So don't know where we are at the moment.

    My code for the LinearMeter is now:

    class Ext_LinearMeter extends Ext_EChartC { protected function create() { $this->x = $this->dataIn[0][1]; $this->y = $this->dataIn[0][2];

    $this->c = new LinearMeter($this->x, $this->y, silverColor(), 0, -1);

    $this->c->setMeter(($this->y)*0.2, ($this->x)*0.1, ($this->x)*0.8, ($this->y)*0.27, Top);

    $this->c->setScale(0, 100, 10);

    // Set 0 - 50 as green (99ff99) zone, 50 - 80 as yellow (ffff66) zone, and 80 - 100 as // red (ffcccc) zone $this->c->addZone(0, 50, 0x99ff99); $this->c->addZone(50, 80, 0xffff66); $this->c->addZone(80, 100, 0xffcccc);

    $this->c->addText(($this->x)*0.04, ($this->y)*0.9, $this->dataIn[0][0], "arialbd.ttf", 8, 0xc00000, BottomLeft);

    $this->c->addTitle($this->options['dbr.echart']['name'], $this->title_font, $this->title_font_size, 0x000000);

    // Add a blue (0000cc) pointer at the specified value $this->c->addPointer($this->dataIn[0][3], 0x0000cc);

    $textBoxObj = $this->c->addText(($this->x)*0.95, ($this->y)*0.93, $this->c->formatValue($this->dataIn[0][3], "2"), "arial.ttf", 8, 0xffffff, BottomRight); $textBoxObj->setBackground(0, 0, -1);

    } }

    Jake

  14. myDBR Team, Key Master

    LinearMeter chart is now directly supported in myDBR. Take a look at documentation for customization options.

    --
    myDBR Team

  15. ajdjackson, Member

    Thanks for this.

    Far more elegant than having to pass all the options along with data in a select query.

    Cheers

    Jake


Reply

You must log in to post.