dbr.chart question

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

    Hi

    I've created a simple MSColumn chart.

    The x-axis are the months of the year and the y-axis are the actual and budget sales for each month.

    I've create a couple of variables which total actual and budget sales for the year and I wish to add these to chart.

    I've got as far as this:

    SELECT 'dbr.chart', 'MScolumn', ''; select 'dbr.chart.options','legend.position', 'bottom';

    select 'dbr.hidecolumn',4;

    select date_format(x.budDate,"%b") as "Month[Mon]", "Budget", sum(ifnull(x.budQty,0)*c.bSP) as "Bud. Sales[BSales]", x.budDate from budgets x join budget_tmp c on x.budProdID = c.bProdID /*left outer join sum_sales_order_tmp e on x.budProdID = e.InvItem and x.budDate = e.InvDate*/ where year(x.budDate) = inYear group by last_day(x.budDate)

    union select date_format(d.aDate,"%b") as "Month[Mon]", "Actual", sum(ifnull(d.aSales,0)) as "Act. Sales[ASales]", d.aDate from act_sales d where year(d.aDate) = inYear group by last_day(d.aDate)

    union select "Total", "Budget", totbudsales, LAST_DAY(date_add(date_format(concat(inYear,"-12-01"),"%Y-%m-%d"), INTERVAL 1 MONTH))

    union select "Total", "Actual", totactsales, LAST_DAY(date_add(date_format(concat(inYear,"-12-01"),"%Y-%m-%d"), INTERVAL 1 MONTH))

    order by 4;

    This produces the chart ok but the as the last pair of values are totals for the year the individual months are small columns in relation to the yearly total ones.

    What I would like to do is to have a secondary y-axis and have the yearly total pair of columns assigned to it.

    Is this possible?

    Many thanks

    Jake

  2. myDBR Team, Key Master

    So basically you would want to combine two column charts as one (one for months, one for totals) so that they would have separate Y-axis? It is not that common to show totals and individual items at the same chart as different scales might confuse user.

    Anyways, you would need a chart like 'MSColumnDY' which does not exists at the moment. Adding one would be relatively easy though, if you need one.

    --
    myDBR Team

  3. ajdjackson, Member

    Hi

    Yes that sounds just like what I need.

    I did notice that there is a MSColumnLineDY but no MSColumnDY so one would be great.

    Many thanks

    Jake

  4. myDBR Team, Key Master

    Jake,
    the latest build includes the MSColumnDY (and MSColumnDY3D chart). The build also has optimized Excel export.

    --
    myDBR Team

  5. ajdjackson, Member

    Hi

    Thanks for doing this.

    I've looked at the example in the demo but I can't seem to get it to work :(

    This is what I've got:

    [code]
    SELECT 'dbr.chart', 'MScolumnDY', '';
    select 'dbr.chart.options','title_font_size', '18px';
    select 'dbr.chart.options','title_color', '0x1254B8';
    select 'dbr.chart.options','legend.position', 'bottom';
    select 'dbr.chart.options', 'scale', 0, 1500000, 100000;
    select 'dbr.chart.options', 'scale2', 0, 12000000, 1000000;

    select 'dbr.hidecolumn',4;

    select
    date_format(x.budDate,"%b") as "Month[Mon]",
    "Budget",
    sum(ifnull(x.budQty,0)*c.bSP) as "Sales",
    x.budDate
    from budgets x
    join budget_tmp c on x.budProdID = c.bProdID
    where year(x.budDate) = inYear
    group by last_day(x.budDate)

    union
    select
    date_format(d.aDate,"%b") as "Month[Mon]",
    "Actual",
    sum(ifnull(d.aSales,0)) as "Sales",
    d.aDate
    from act_sales d
    where year(d.aDate) = inYear
    group by last_day(d.aDate)

    order by 4;
    {/code]

    What I'm trying to do is to plot the Monthly Actual v Budget Sales and then have the last 2 columns showing the yearly Actual and the total budget sales for the year.

    Cheers

    Jake

  6. myDBR Team, Key Master

    Jake,
    you do not have the yearly actual and the total budget sales for the year in the query anywhere. Just the items for the y-axis 1.

    You also do not need to use dbr.hidecolumn with charts.

    --
    myDBR Team

  7. ajdjackson, Member

    DOH!

    Still not getting it right. It must be how I'm structuring the query.

    I've created two variables - totbudsale and totactsales - prior to creating the chart.

    declare totbudsales float; declare totactsales float;

    select sum(ifnull(x.budQty,0)*c.bSP) into totbudsales from budgets x join budget_tmp c on x.budProdID = c.bProdID where year(x.budDate) = inYear;

    select sum(ifnull(d.aSales,0)) into totactsales from act_sales d where year(d.aDate) = inYear;

    SELECT 'dbr.chart', 'MScolumnDY', ''; select 'dbr.chart.options','title_font_size', '18px'; select 'dbr.chart.options','title_color', '0x1254B8'; select 'dbr.chart.options','legend.position', 'bottom'; select 'dbr.chart.options', 'scale', 0, 1500000, 100000; select 'dbr.chart.options', 'scale2', 0, 12000000, 1000000;

    select date_format(x.budDate,"%b") as "Month[Mon]", "Budget", sum(ifnull(x.budQty,0)*c.bSP) as "Sales", x.budDate from budgets x join budget_tmp c on x.budProdID = c.bProdID /*left outer join sum_sales_order_tmp e on x.budProdID = e.InvItem and x.budDate = e.InvDate*/ where year(x.budDate) = inYear group by last_day(x.budDate)

    union select date_format(d.aDate,"%b") as "Month[Mon]", "Actual", sum(ifnull(d.aSales,0)) as "Sales", d.aDate from act_sales d where year(d.aDate) = inYear group by last_day(d.aDate)

    union select "Total", "Budget", totbudsales, LAST_DAY(date_add(date_format(concat(inYear,"-12-01"),"%Y-%m-%d"), INTERVAL 1 MONTH))

    union select "Total", "Actual", totactsales, LAST_DAY(date_add(date_format(concat(inYear,"-12-01"),"%Y-%m-%d"), INTERVAL 1 MONTH))

    order by 4;

    Cheers and thanks

    Jake

  8. myDBR Team, Key Master

    When you have a double Y-chart, myDBR will by default put the last set in the second Y-axis. You can however place the sets to the axis using the series_axis-option.

    An example.

    --
    myDBR Team

  9. ajdjackson, Member

    Great - working now.

    Seeing your example indetail really helped.

    Thanks

    Jake

  10. ajdjackson, Member

    Hi

    Apologies for resurrecting an old question but I've noticed an issue with the tooltips with this chart.

    I've created a chart as below:

    declare @sdate date,@edate date,@fedate date,@fyr int,@bnum int,@mact float,@mbud float,@cmax float,@cmax2 float,@myact float,@mybud float;

    select @edate=eomonth(max(InvMon)) from [pharma].[dbo].[vw_mon_inv_sales];

    select @bnum=paramval from [pharma].[dbo].[tblparams] where [paramType]='budnum';

    select @fyr=FiscalYear from [pharma].[dbo].[tbldates] where CurDate=convert(date,getdate());

    select @sdate=AccYearSDate from [pharma].[dbo].[tblAccountYears_v2] where [AccYear]=@fyr; select @fedate=dateadd(month,1,AccYearEDate) from [pharma].[dbo].[tblAccountYears_v2] where [AccYear]=@fyr;

    select @mact= max(mval) from ( select sum(net)/1000000 as mval from [pharma].[dbo].[vw_mon_inv_sales] where invmon between @sdate and @edate group by invmon ) a;

    select @mbud = max(mval) from ( select sum(bval)/1000000 as mval from [pharma].[dbo].[vw_mon_bud_sales] where bnum=@bnum and byear=@fyr group by bper ) a;

    select @myact= sum(net)/1000000 from [pharma].[dbo].[vw_mon_inv_sales] where invmon between @sdate and @edate;

    select @mybud = sum(bval)/1000000 from [pharma].[dbo].[vw_mon_bud_sales] where bnum=@bnum and byear=@fyr and bper<=(select FiscalPeriod from [pharma].[dbo].[tbldates] where CurDate=@edate);

    select @cmax = ceiling(iif(@mbud>@mact,@mbud,@mact)); select @cmax2 = ceiling(iif(@mybud>@myact,@mybud,@myact));

    select 'dbr.chart','MSColumnDY','',600,175;; select 'dbr.chart.color', '0x00FF00','0xFF0000' ; select 'dbr.chart.options','format','SVG'; select 'dbr.chart.options','showLegend',0; select 'dbr.chart.options','rotateNames',45; select 'dbr.chart.options','axis','','£M'; select 'dbr.chart.options', 'series_axis', 'Actual YTD', 2; select 'dbr.chart.options', 'series_axis', 'Budget YTD', 2; select 'dbr.chart.options', 'scale', 0, @cmax, 1; select 'dbr.chart.options', 'scale2', 0, @cmax2, 5; select 'dbr.hidecolumn','adate'; select 'dbr.chart.options', 'label_color', 'Actual YTD', '0x00FF00'; select 'dbr.chart.options', 'label_color', 'Budget YTD', '0xFF0000';

    with cte_budper as (select FiscalPeriod as bper, max(curDate) as bdate from [pharma].[dbo].[tbldates] where FiscalYear=@fyr group by FiscalPeriod) select format(eomonth(InvMon),'MMM') as SMonth, 'Actual' as SType, sum(Net)/1000000 as sVal, eomonth(InvMon) as adate from [pharma].[dbo].[vw_mon_inv_sales] where InvMon>=@sdate group by eomonth(InvMon) union select format(b.bdate,'MMM') as SMonth, 'Budget' as SType, sum(a.bval)/1000000 as sVal, eomonth(b.bdate) from [pharma].[dbo].[vw_mon_bud_sales] a join cte_budper b on a.bper=b.bper where eomonth(b.bdate)>=eomonth(@sdate) and a.byear=@fyr and a.bnum=@bnum group by b.bdate union select 'YTD', 'Budget YTD', sum(bval)/1000000, @fedate from [pharma].[dbo].[vw_mon_bud_sales] where bnum=@bnum and byear=@fyr and bper<=(select FiscalPeriod from [pharma].[dbo].[tbldates] where CurDate=@edate) union select 'YTD', 'Actual YTD', sum(Net)/1000000, @fedate from [pharma].[dbo].[vw_mon_inv_sales] where invmon between @sdate and @edate order by 4,2;

    The chart displays correctly and the tooltips for the individual months are also correct. However, even although the columns for the YTD values are correct the tooltips are reversed.

    Any thoughts?

    Thanks

    Jake

  11. myDBR Team, Key Master

    The latest build should fix the tooltips on the columns assigned to the second axis.

    --
    myDBR Team

  12. ajdjackson, Member

    Thanks - works great!

    Jake


Reply

You must log in to post.