The above image is of my chart.
The default color of this kendo chart is not changing - I tried to set the color but it didn't work.
Here is my code:
#(Html.Kendo().Chart(item.UsageData)
.Name(item.Type)
.ChartArea(ca => ca.Background("transparent").Height(380))
.Legend(l => l.Visible(true).Position(ChartLegendPosition.Bottom))
.Series(s => s.Column("Cost", "lblUsage").Labels(l => l.Visible(true).Template("$ #= value #")))
.CategoryAxis(x => x.Categories(item.UsageData.Select(y => y.lblUsage)).Labels(l => l.Rotation(-25)).MajorGridLines(m => m.Visible(false)).MinorGridLines(minor => minor.Visible(false)))
.Tooltip(tooltip => tooltip.Visible(true).Template("#= dataItem.lblUsage #: #= value # $").Padding(5).Background("#3893ae"))
)
Related
I'm trying to create bar plot with labels on bars. Position of labels and color of labels depends on column of dataframe. Also, I would like to color bars by column.
My data:
data = {
'Survived': ['0', '1'],
'count': [500, 100],
'label_position': ['R', 'L']
}
df = pd.DataFrame(data)
I tried to create following plot:
import seaborn.objects as so
p = (
so.Plot(df, x='count', y='Survived')
.add(so.Bar(alpha=1), color='Survived')
.add(
so.Text({"fontweight": "bold"}),
text='count',
halign='label_position',
color="label_position"
)
.scale(
halign={'L':'left', 'R':'right'},
color={'L':'black', 'R':'white'}
)
)
p.plot()
but this code raises following error:
PlotSpecError: Scale setup failed for the `color` variable. See the traceback above for more information.
because both visualizations have attribute color.
I'm able co color bars, or the text, but not both at once.
Colored bars:
color the bars
Colored text:
color the text
Is there any posibility to color both?
If we see the traceback above for more information as the exception message suggests, it says
ValueError: No entry in color dictionary for '0', '1'
So we could try adding entries for those keys:
(
so.Plot(df, x='count', y='Survived')
.add(so.Bar(alpha=1), color='Survived')
.add(
so.Text({"fontweight": "bold"}),
text='count',
halign='label_position',
color="label_position",
)
.scale(
halign={'L':'left', 'R':'right'},
color={'L':'black', 'R':'white', '0': 'black', '1': 'white'}, # <-----
)
)
That works but now we have some entries in the legend that we probably don't want. There's not in general a way to control what shows up in the legend independently of what actually gets mapped for Nominal scales, but for this particular plot the color encoding is redundant anyway so we don't actually need the legend:
(
so.Plot(df, x='count', y='Survived')
.add(so.Bar(alpha=1), color='Survived', legend=False) # <-----
.add(
so.Text({"fontweight": "bold"}),
text='count',
halign='label_position',
color="label_position",
)
.scale(
halign={'L':'left', 'R':'right'},
color={'L':'black', 'R':'white', '0': 'black', '1': 'white'},
)
)
I have an ordinal bar chart that can have quite a lot of values on the x-axis. I'm trying to add a range chart to navigate the bar chart, as in this example
https://dc-js.github.io/dc.js/examples/focus-ordinal-bar.html
Here is my chart with the range chart.
Here it is filtered.
When I make a selection on the range chart, the main chart filters to those values as expected. However, all the other charts update as if this was a selection.
The behaviour I'm looking for is for no filtering to happen, all that should change is the bars shown on the main chart for navigation purposes. This is the way it behaves in the Focus Ordinal Bar example.
My bar chart and range chart below. I've tried changing the group and dimension of the range chart to copies of the group and dimension, but that didn't seem to have any effect.
barChartTemplate
.dimension (dimension)
.group (group)
.x (scaleLinear ().domain (linear_domain))
.xUnits (dc.units.integers)
.keyAccessor (kv => group.ord2int (kv.key))
.elasticY (true)
.brushOn (false)
.dimension (dimension)
.mouseZoomable (true)
.zoomScale ([4, 8])
.title (function (kv) {
return kv.key;
})
var rangeChart = dc.barChart ('#range');
rangeChart.filterHandler (x => {});
rangeChart
.dimension (dimension)
.group (group)
.margins ({left: 40, top: 2, right: 40, bottom: 0})
.height (20)
.x (scaleLinear ().domain (linear_domain))
.xUnits (dc.units.integers)
.keyAccessor (kv => group.ord2int (kv.key))
.valueAccessor (x => {
return x.value.count;
})
.elasticY (true)
.brushOn (true)
.centerBar (true)
.transitionDuration (0);
barChartTemplate.rangeChart (rangeChart);
I am attempting to create a pie chart using the gruff gem, but my chart is a black abyss regardless of what I do. This is my code:
association_disposition_pie_chart = Gruff::Pie.new
association_disposition_pie_chart.title = "Visual Pie Graph Test"
association_disposition_pie_chart.data 'Solved', 10
association_disposition_pie_chart.data 'Action Required', 50
association_disposition_pie_chart.theme = {
:colors => ['#A5D8D8', '#EFAD1C'],
:font_color => 'black',
:background_colors => 'white'
}
association_disposition_pie_chart.write("association_disposition_pie_chart.jpg")
Why is this creating a black pie chart? The background is white, the font_color is black, but so is the entire chart. I want the chart pieces to be the colors specified in :colors.
EDIT
Screenshot:
http://i39.tinypic.com/33ne1r6.jpg
This is mentioned in the documentation:
You can set a theme manually. Assign a hash to this method before you send your data.
graph.theme = {
:colors => %w(orange purple green white red),
:marker_color => 'blue',
:background_colors => %w(black grey)
}
:background_image => 'squirrel.png' is also possible.
(Or hopefully something better looking than that.)
Although the source is more helpful:
# File 'lib/gruff/base.rb', line 300
def theme=(options)
reset_themes()
defaults = {
:colors => ['black', 'white'],
:additional_line_colors => [],
:marker_color => 'white',
:font_color => 'black',
:background_colors => nil,
:background_image => nil
}
#theme_options = defaults.merge options
#colors = #theme_options[:colors]
#marker_color = #theme_options[:marker_color]
#font_color = #theme_options[:font_color] || #marker_color
#additional_line_colors = #theme_options[:additional_line_colors]
render_background
end
I think maybe the problem is your colors attribute - :colors => ['#A5D8D8', '#EFAD1C'] - as Shaun Frost Duke Jackson mentioned, it looks like you need to use add_color('#c0e9d3') to do that, but the documentation isn't clear where you do that if you're defining the theme in line. It might be easier to add your own theme in the THEMES module:
LUIGIS_THEME = {
:colors => [
'#A5D8D8',
'#EFAD1C'
],
:marker_color => '#55ae36',
:font_color => 'black',
:background_colors => 'white'
}
which is then called with g.theme = Gruff::Themes::LUIGIS_THEME
While using imagemagick-no-hdri and the default rmagick gem the pie graphs would become black and white. I was able to fix this issue by doing the following
Install imagemagick
git clone git#github.com:rmagick/rmagick.git
gem build rmagick.gemspec
gem install ./rmagick-2.13.2.gem
I'm trying to position some content vertically centered in a bounding_box. With a single text this is no problem:
bounding_box([0, bounds.top], :width => pdf.bounds.right, :height => pdf.bounds.top) do
text "vertically aligned in the surrounding box", :valign => :center
end
But what can I do if a have multiple elements in my bounding box:
bounding_box([0, bounds.top], :width => pdf.bounds.right, :height => pdf.bounds.top) do
text "vertically aligned in the surrounding box", :valign => :center
text "vertically aligned in the surrounding box", :valign => :center
end
That won't work, the text is overlaid when you try this...
I'm looking for a way to group the whole content of the bounding_box and then align that whole group vertically. Is there any way to do this with prawn??
Thanks a lot for your help!
Chris
If you only have text lines, you can still use formatted_text with \n in your text :
formatted_text [
{ text: "#{line1}\n" },
{ text: "#{line2}" }
],
valign: :center,
leading: 6
I'm still trying to figure out how to handle a picture/legend group, since even tables don't seem to do the trick.
I'm having my first go at using Google charts using a Ruby wrapper called gchartrb. My first attempt was to draw a bar chart, which works fairly well, except that the largest value (Trend 2 - 800) hits the top of the y axis. I'm guessing this is a Google Charts issue, but I was wondering if there was a way around this problem so all values scale correctly?
labels = [1, 2, 3, 4]
GoogleChart::BarChart.new('800x200', "Bar Chart", :vertical, false) do |bc|
bc.axis :x, :labels => labels,
:color => '000000' # Months
bc.axis :y, :labels => [0, 100, 200, 300, 400, 500, 600, 700, 800, 900],
:color => '000000' # Number of books
bc.data "Trend 1", [100,200,300,400], '0000ff'
bc.data "Trend 2", [500,600,700,800], 'ff0000'
bc.width_spacing_options :bar_width => 50, :bar_spacing => 0, :group_spacing => 0
puts "\nBar Chart"
puts bc.to_url
end
Gave up on this gem and ended up using Google Charts directly.
for scaling issue, there is an option called 'range' for bc.axis attribute like,
bc.axis :y, :color => '000000', :range => [0,max_scale_value]
you can set max_scale_value to me maximum value of your data values.
1) If you are displaying bars side by side, you can set max_scale_value to 800, as per your data. i.e. max value from both of your arrays.
2) If you are displaying stacked bars(one above the other), then you should set max_scale_value to be maximum of [(100+500),(200+600),(300+700),(400+800)]
3) you need to remove labels property for y -axis,because it will automatically scale as per the values and give you labels.
thus, you wont have the scaling issue.
Hope it helps :)